-
Notifications
You must be signed in to change notification settings - Fork 0
/
honeycheck_rw_ssh.py
65 lines (57 loc) · 2.2 KB
/
honeycheck_rw_ssh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
# coding: utf-8
import paramiko
import random
import string
import sys
def generate_path(tempdir):
output_string = ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(10))
path = "%s/%s" %(tempdir, output_string)
return path
def generate_contents():
output_string = ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(10))
return output_string
def write_file(ip_address, username, password, path, contents):
print "[+] Doing write file..."
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(ip_address, username=username, password=password)
print "[!] Logged in!"
except Exception:
sys.exit("[-] Login Failed!")
try:
command = "echo '%s' >> %s" %(contents, path)
ssh.exec_command(command)
except Exception:
sys.exit("[-] Command execution failed! Possibly a pot?")
print "[+] File written..."
def read_file(ip_address, username, password, path, contents):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(ip_address, username=username, password=password)
print "[!] Logged in!"
except Exception:
sys.exit("[-] Login Failed!")
try:
command = "cat %s" %(path)
stdin, stdout, stderr = ssh.exec_command(command)
if contents in stdout.read():
print "[+] Probably not a pot! Contents found"
else:
print "[!] Possibly a pot! Contents not found!"
ssh.exec_command("rm %s" %(path))
except Exception:
sys.exit("[-] Something went wrong. Possibly a pot.")
def check_pot(ip_address, username, password):
path = generate_path(tempdir="/tmp")
contents = generate_contents()
write_file(ip_address, username, password, path, contents)
read_file(ip_address, username, password, path, contents)
def main(args):
if len(args) != 4:
sys.exit("use: %s <ip address> <username> <password>" %(args[0]))
check_pot(ip_address=args[1], username=args[2], password=args[3])
if __name__ == "__main__":
main(args=sys.argv)