Created
June 22, 2020 15:03
-
-
Save msterhuj/e9d45bcebded107a09c614e2d6f17dcb to your computer and use it in GitHub Desktop.
Memcache udp scanner on python3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
TIME_OUT = 1 | |
IP_LIST = "ips.txt" # Ip list for check | |
OUTPUT_FILE = "vuln.txt" | |
PAYLOAD = "\x00\x00\x00\x00\x00\x01\x00\x00\x73\x74\x61\x74\x73\x0d\x0a" # ........stats | |
def scan(ip): | |
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
client.settimeout(TIME_OUT) | |
try: | |
client.sendto(bytes(PAYLOAD, encoding='utf8'), | |
(ip, 11211)) | |
data = client.recvfrom(4096) | |
length = len(data[0]) | |
if length > 200: | |
print("The IP has vul of memcached: " + ip) | |
save(ip) | |
else: | |
print("The IP possible vul of memcached: " + ip) | |
except KeyboardInterrupt: | |
print("Exiting.") | |
exit(-1) | |
except socket.timeout: | |
print("No reply from " + ip + " after " + str(TIME_OUT) + "s") | |
finally: | |
client.close() | |
def save(ip): | |
with open(OUTPUT_FILE, "a+") as file: | |
file.write(ip + "\n") | |
file.close() | |
# Author @MsterHuj | |
if __name__ == '__main__': | |
f = open(IP_LIST, "r") | |
for l in f: | |
scan(l.replace('\n', '')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment