-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPySPLOIT.py
More file actions
68 lines (51 loc) · 1.59 KB
/
Copy pathPySPLOIT.py
File metadata and controls
68 lines (51 loc) · 1.59 KB
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
66
67
68
import pyfiglet
import socket
import os
import sys
import subprocess
import threading
import time
from datetime import datetime
from queue import Queue
from metasploit import msfrpc
subprocess.call('clear', shell=True)
ascii_banner = pyfiglet.figlet_format("PySCANNER")
print(ascii_banner)
# Set socket timeout to a higher value to avoid missing open ports
socket.setdefaulttimeout(1.0)
# Declare list to store discovered ports
discovered_ports = []
# Lock thread during print so we get cleaner outputs
print_lock = threading.Lock()
# Notify user
target = input('Target: ')
# Convert target to IP address, if it is a hostname
# This requires that it actually resolves
t_IP = socket.gethostbyname(target)
print(f'Scanning Host for Open Ports: {t_IP}')
# Define port scan function
def portscan(port):
# Create socket object
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Try to connect
try:
# Create/open connection
conx = s.connect((t_IP, port))
# Don't let thread contention screw up printing
with print_lock:
print(f"port {port} is open")
discovered_ports.append(str(port))
# Create client object
client = msfrpc.MsfRpcClient('your_username', 'your_password')
# Authenticate with the client
client.login()
# List all available exploits
exploits = client.modules.exploits
# Print the names of the available exploits
for exploit in exploits:
print(exploit['name'])
# Select a specific exploit by name
exploit_name = 'windows/smb/ms17_010_eternalblue'
client.modules.use(exploit_name)
# Close connection
con