TLS ClientHello parser and JA3/JA4-style fingerprint toolkit for MoonBit traffic-audit probes.
Dependencies
moon add yhsrtty/moontls-parserimport {
"yhsrtty/moontls-parser@0.1.2",
}{
"deps": {
"yhsrtty/moontls-parser": "0.1.2"
}
}git clone https://github.com/yhsrtty/MoonTLS-Parser.git
cd MoonTLS-Parser
moon check --deny-warn
moon test --deny-warn
moon run cmd/mainlet parsed = parse_tls_record(packet_bytes)
match parsed {
Ok(ClientHelloRecord(hello)) => {
println(hello.server_name)
println(hello.ja3_digest())
println(hello.to_json())
}
Ok(ServerHelloRecord(hello)) => {
println(hello.selected_alpn)
println(hello.ja4s_a())
println(hello.to_json())
}
Ok(AlertRecord(alert)) => {
println(alert.description_string())
}
Ok(CertificateRecord(cert)) => {
println(cert.cert_lengths)
}
Ok(GenericRecord(ty, payload)) => {
println("Other TLS Record")
}
Err(err) => println(err)
}let stream = ClientHelloStream::new()
let a = stream.push(first_fragment)
let b = stream.push(second_fragment)moon test --deny-warn
moon check --deny-warn
moon infopub struct ClientHello {
legacy_version : UInt16
record_version : UInt16
cipher_suites : Array[UInt16]
compression_methods : Array[Byte]
extensions : Array[UInt16]
supported_groups : Array[UInt16]
ec_point_formats : Array[Byte]
signature_algorithms : Array[UInt16]
alpn_protocols : Array[String]
server_name : String?
raw_length : Int
} derive(Debug)type Sha256pub enum TlsRecord {
ClientHelloRecord(ClientHello)
ServerHelloRecord(ServerHello)
AlertRecord(TlsAlert)
CertificateRecord(TlsCertificate)
ClientKeyExchangeRecord(ClientKeyExchange)
ServerKeyExchangeRecord(ServerKeyExchange)
NewSessionTicketRecord(NewSessionTicket)
EncryptedExtensionsRecord(EncryptedExtensions)
HelloRequestRecord(HelloRequest)
HelloVerifyRequestRecord(HelloVerifyRequest)
CertificateRequestRecord(CertificateRequest)
CertificateVerifyRecord(CertificateVerify)
FinishedRecord(Finished)
GenericRecord(TlsRecordType, Bytes)
} derive(Debug)let CONTENT_TYPE_CHANGE_CIPHER_SPEC : Bytelet GROUP_SECP256R1 : UInt16let HANDSHAKE_TYPE_HELLO_REQUEST : Bytelet SIG_SCHEME_RSA_PKCS1_SHA256 : UInt16fn add_custom_client_fingerprint(fp : String, client_type : String, desc : String) -> Unitfn add_custom_server_fingerprint(fp : String, server_type : String, desc : String) -> UnitTLS ClientHello parser and JA3/JA4-style fingerprint toolkit for MoonBit traffic-audit probes.
Dependencies