Path: blob/dev/pkg/js/libs/structs/smbexploit.js
2070 views
const header = bytes.Buffer();12// Create the SMB header first3header.append(structs.pack("B", 254)); // magic4header.append("SMB");5header.append(structs.pack("H", 64)); // header size6header.append(structs.pack("H", 0)); // credit charge7header.append(structs.pack("H", 0)); // channel sequence8header.append(structs.pack("H", 0)); // reserved9header.append(structs.pack("H", 0)); // negotiate protocol command10header.append(structs.pack("H", 31)); // credits requested11header.append(structs.pack("I", 0)); // flags12header.append(structs.pack("I", 0)); // chain offset13header.append(structs.pack("Q", 0)); // message id14header.append(structs.pack("I", 0)); // process id15header.append(structs.pack("I", 0)); // tree id16header.append(structs.pack("Q", 0)); // session id17header.append(structs.pack("QQ", [0, 0])); // signature1819// Create negotiation packet20const negotiation = bytes.Buffer();21negotiation.append(structs.pack("H", 0x24)); // struct size22negotiation.append(structs.pack("H", 8)); // amount of dialects23negotiation.append(structs.pack("H", 1)); // enable signing24negotiation.append(structs.pack("H", 0)); // reserved25negotiation.append(structs.pack("I", 0x7f)); // capabilities26negotiation.append(structs.pack("QQ", [0, 0])); // client guid27negotiation.append(structs.pack("I", 0x78)); // negotiation offset28negotiation.append(structs.pack("H", 2)); // negotiation context count29negotiation.append(structs.pack("H", 0)); // reserved30negotiation.append(structs.pack("H", 0x0202)); // smb 2.0.2 dialect31negotiation.append(structs.pack("H", 0x0210)); // smb 2.1.0 dialect32negotiation.append(structs.pack("H", 0x0222)); // smb 2.2.2 dialect33negotiation.append(structs.pack("H", 0x0224)); // smb 2.2.4 dialect34negotiation.append(structs.pack("H", 0x0300)); // smb 3.0.0 dialect35negotiation.append(structs.pack("H", 0x0302)); // smb 3.0.2 dialect36negotiation.append(structs.pack("H", 0x0310)); // smb 3.1.0 dialect37negotiation.append(structs.pack("H", 0x0311)); // smb 3.1.1 dialect38negotiation.append(structs.pack("I", 0)); // padding39negotiation.append(structs.pack("H", 1)); // negotiation context type40negotiation.append(structs.pack("H", 38)); // negotiation data length41negotiation.append(structs.pack("I", 0)); // reserved42negotiation.append(structs.pack("H", 1)); // negotiation hash algorithm count43negotiation.append(structs.pack("H", 32)); // negotiation salt length44negotiation.append(structs.pack("H", 1)); // negotiation hash algorithm SHA51245negotiation.append(structs.pack("H", 1)); // negotiation hash algorithm SHA51246negotiation.append(structs.pack("QQ", [0, 0])); // salt part 147negotiation.append(structs.pack("QQ", [0, 0])); // salt part 248negotiation.append(structs.pack("H", 3)); // unknown??49negotiation.append(structs.pack("H", 10)); // data length unknown??50negotiation.append(structs.pack("I", 0)); // reserved unknown??51negotiation.append("\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00"); // unknown5253const packet = bytes.Buffer();54packet.append(header.bytes());55packet.append(negotiation.bytes());5657const netbios = bytes.Buffer();58netbios.append(structs.pack("H", 0)); // NetBIOS sessions message (should be 1 byte but whatever)59netbios.append(structs.pack("B", 0)); // just a pad to make it 3 bytes60netbios.append(structs.pack("B", packet.len())); // NetBIOS length (should be 3 bytes but whatever, as long as the packet isn't 0xff+ bytes)6162const final = bytes.Buffer();63final.append(netbios.bytes());64final.append(packet.bytes());6566console.log("Netbios", netbios.hex(), netbios.len());67console.log("Header", header.hex(), header.len());68console.log("Negotation", negotiation.hex(), negotiation.len());69console.log("Packet", final.hex(), final.len());7071const c = require("nuclei/libnet");72let conn = c.Open("tcp", "118.68.186.114:445");73conn.Send(final.bytes(), 0);74let bytesRecv = conn.Recv(0, 4);75console.log("recv Bytes", bytesRecv);76let size = structs.unpack("I", bytesRecv)[0];77console.log("Size", size);78let data = conn.Recv(0, size);79console.log("Data", data);8081// TODO: Add hexdump helpers8283version = structs.unpack("H", data.slice(68,70))[0]84context = structs.unpack("H", data.slice(70,72))[0]8586console.log("Version", version);87console.log("Context", context);8889if (version != 0x0311){90console.log("SMB version ", version, "was found which is not vulnerable!");91} else if (context != 2) {92console.log("Server answered with context", context, " which indicates that the target may not have SMB compression enabled and is therefore not vulnerable!");93} else {94console.log("SMB version ", version, " with context ", context, " was found which indicates SMBv3.1.1 is being used and SMB compression is enabled, therefore being vulnerable to CVE-2020-0796!");95}96conn.Close();9798