Debug Server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
1.0 KiB

  1. # Using the source code and instructions from: https://inc0x0.com/tcp-ip-packets-introduction/tcp-ip-packets-3-manually-create-and-send-raw-tcp-ip-packets/
  2. import socket
  3. s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)
  4. s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
  5. # b converts string into byte format
  6. ip_header = b'\x45\x00\x00\x28' # Version, IHL, Type of Service | Total Length
  7. ip_header += b'\xab\xcd\x00\x00' # Identification | Flags, Fragment Offset
  8. ip_header += b'\x40\x06\xa6\xec' # TTL, Protocol | Header Checksum
  9. ip_header += b'\x0a\x0a\x0a\x02' # Source Address
  10. ip_header += b'\x0a\x0a\x0a\x01' # Destination Address
  11. tcp_header = b'\x30\x39\x00\x50' # Source Port | Destination Port
  12. tcp_header += b'\x00\x00\x00\x00' # Sequence Number
  13. tcp_header += b'\x00\x00\x00\x00' # Acknowledgement Number
  14. tcp_header += b'\x50\x02\x71\x10' # Data Offset, Reserved, Flags | Window Size
  15. tcp_header += b'\xe6\x32\x00\x00' # Checksum | Urgent Pointer
  16. packet = ip_header + tcp_header
  17. s.sendto(packet, ('10.10.10.1', 0))