-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for tls impersonate (#126)
* Adding support for tls impersonate * fixing gh action * removing types - helpers should be used * running examples * fixing command
- Loading branch information
Showing
11 changed files
with
359 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"crypto/tls" | ||
"log" | ||
|
||
"github.com/projectdiscovery/fastdialer/fastdialer" | ||
"github.com/projectdiscovery/fastdialer/fastdialer/ja3/impersonate" | ||
) | ||
|
||
func main() { | ||
options := fastdialer.DefaultOptions | ||
|
||
// Create new dialer using NewDialer(opts fastdialer.options) | ||
fd, err := fastdialer.NewDialer(fastdialer.DefaultOptions) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Configure Cache if required | ||
// memory based (also support Hybrid and Disk Cache) | ||
options.CacheType = fastdialer.Memory | ||
options.CacheMemoryMaxItems = 100 | ||
|
||
ctx := context.Background() | ||
|
||
target := "www.projectdiscovery.io" | ||
|
||
conn, err := fd.DialTLSWithConfigImpersonate(ctx, "tcp", target+":443", &tls.Config{InsecureSkipVerify: true}, impersonate.Random, nil) | ||
if err != nil || conn == nil { | ||
log.Fatalf("couldn't connect to target: %s", err) | ||
} | ||
defer conn.Close() | ||
log.Println("connected to the target") | ||
|
||
// To look up Host/ Get DNS details use | ||
data, err := fd.GetDNSData(target) | ||
if err != nil || data == nil { | ||
log.Fatalf("couldn't retrieve dns data: %s", err) | ||
} | ||
|
||
// To Print All Type of DNS Data use | ||
jsonData, err := data.JSON() | ||
if err != nil { | ||
log.Fatalf("failed to marshal json: %s", err) | ||
} | ||
log.Println(jsonData) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ja3 | ||
|
||
import "fmt" | ||
|
||
// ErrExtensionNotExist is returned when an extension is not supported by the library | ||
type ErrExtensionNotExist string | ||
|
||
// Error is the error value which contains the extension that does not exist | ||
func (e ErrExtensionNotExist) Error() string { | ||
return fmt.Sprintf("Extension does not exist: %s\n", string(e)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// ja3 is a package for creating JA3 fingerprints from TLS clients. | ||
// The original extension map and numeric id=>tls extension mapping is from /~https://github.com/CUCyber | ||
package ja3 | ||
|
||
import ( | ||
utls "github.com/refraction-networking/utls" | ||
"golang.org/x/exp/maps" | ||
) | ||
|
||
// extMap maps extension values to the TLSExtension object associated with the | ||
// number. Some values are not put in here because they must be applied in a | ||
// special way. For example, "10" is the SupportedCurves extension which is also | ||
// used to calculate the JA3 signature. These JA3-dependent values are applied | ||
// after the instantiation of the map. | ||
var defaultExtensionMap = map[string]utls.TLSExtension{ | ||
"0": &utls.SNIExtension{}, | ||
"5": &utls.StatusRequestExtension{}, | ||
// These are applied later | ||
// "10": &tls.SupportedCurvesExtension{...} | ||
// "11": &tls.SupportedPointsExtension{...} | ||
"13": &utls.SignatureAlgorithmsExtension{ | ||
SupportedSignatureAlgorithms: []utls.SignatureScheme{ | ||
utls.ECDSAWithP256AndSHA256, | ||
utls.PSSWithSHA256, | ||
utls.PKCS1WithSHA256, | ||
utls.ECDSAWithP384AndSHA384, | ||
utls.PSSWithSHA384, | ||
utls.PKCS1WithSHA384, | ||
utls.PSSWithSHA512, | ||
utls.PKCS1WithSHA512, | ||
utls.PKCS1WithSHA1, | ||
}, | ||
}, | ||
"16": &utls.ALPNExtension{ | ||
AlpnProtocols: []string{"h2", "http/1.1"}, | ||
}, | ||
"18": &utls.SCTExtension{}, | ||
"21": &utls.UtlsPaddingExtension{GetPaddingLen: utls.BoringPaddingStyle}, | ||
"23": &utls.UtlsExtendedMasterSecretExtension{}, | ||
"28": &utls.FakeRecordSizeLimitExtension{}, | ||
"35": &utls.SessionTicketExtension{}, | ||
"43": &utls.SupportedVersionsExtension{Versions: []uint16{ | ||
utls.GREASE_PLACEHOLDER, | ||
utls.VersionTLS13, | ||
utls.VersionTLS12, | ||
utls.VersionTLS11, | ||
utls.VersionTLS10}}, | ||
"44": &utls.CookieExtension{}, | ||
"45": &utls.PSKKeyExchangeModesExtension{ | ||
Modes: []uint8{ | ||
utls.PskModeDHE, | ||
}}, | ||
"51": &utls.KeyShareExtension{KeyShares: []utls.KeyShare{}}, | ||
"13172": &utls.NPNExtension{}, | ||
"65281": &utls.RenegotiationInfoExtension{ | ||
Renegotiation: utls.RenegotiateOnceAsClient, | ||
}, | ||
} | ||
|
||
func getExtensionMap() map[string]utls.TLSExtension { | ||
return maps.Clone(defaultExtensionMap) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// impersonate package contains strategy to impersonate a client and define an alias for the internal | ||
// client tls spefications | ||
package impersonate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package impersonate | ||
|
||
import ( | ||
utls "github.com/refraction-networking/utls" | ||
) | ||
|
||
// Strategy is the type of strategy to use for impersonation | ||
type Strategy uint8 | ||
|
||
const ( | ||
// None is the default strategy which use the default client hello spec | ||
None Strategy = iota | ||
// Random is the strategy which use a random client hello spec | ||
Random | ||
// JA3 or Raw is the strategy which parses a client hello spec from ja3 full string | ||
Custom | ||
) | ||
|
||
// Identity contains the structured client hello spec | ||
type Identity utls.ClientHelloSpec |
Oops, something went wrong.