【信息收集】用python对目标网站进行 C段扫描 与 旁站扫描(八)

一、旁站探测

1.1 设计思想

1.旁站的概念
​ 旁站指的是同一服务器上的其他网站,很多时候,有些网站可能不是那么容易访问。那么,可以查看该网站所在的服务器上是否还有其他网站。如果有其他网站的话,可以先拿下其他网站的webshell,然后再提权拿到服务器的权限,最后就自然可以拿下该网站。

2.设计思想
封装domain数据以post方法请求 webscan.cc,进行旁站扫描,本例中返回与baidu.com在同站上的其他网站的域名。

1.2 代码

def site(domain):
	headers = {
    
    
        'Accept': '*/*',
        'Accept-Language': 'en-US,en;q=0.8',
        'Cache-Control': 'max-age=0',
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',
        'Connection': 'keep-alive',
        'Referer': 'http://www.baidu.com/'
    }
    data = {
    
    
        'domain': domain
    }
    data_json = json.dumps(data)
    results = requests.post('https://www.webscan.cc/', headers=headers, data=data_json, verify=False)
    soup = BeautifulSoup(results.content, 'html.parser')
    job_bt = soup.findAll('li')
    # print(job_bt)
    number = 1
    res_list = []
    try:
        for i in job_bt:
            result = {
    
    
                '序号': number,
                '名称': i.span.string,
                '域名': i.a.string
            }
            number += 1
            res_list.append(result)
    except Exception as e:
        pass
    print(res_list)

if __name__ == '__main__':
    site("baidu.com")

返回结果:

[
{
    
    '序号': 1, '名称': 'Null', '域名': 'tools.ggogle.com'}, 
{
    
    '序号': 2, '名称': 'P-Learning - Corsi Di Formazione Professionale', '域名': 'www.p-learning.com'}, 
{
    
    '序号': 3, '名称': 'Null', '域名': 'www.1gyw8u.cyou'}, 
{
    
    '序号': 4, '名称': '仍玩游戏-仍爱玩那些让人热血沸腾的游戏', '域名': 'www.rr55.com'}, {
    
    '序号': 5, '名称': 'Null', '域名': 'www.1rw7no.cyou'}, 
{
    
    '序号': 6, '名称': 'Null', '域名': 'gw.fzzqcdn.com'}, 
{
    
    '序号': 7, '名称': 'Null', '域名': 'www.104uzb.cyou'},
{
    
    '序号': 8, '名称': 'Null', '域名': 'js-gt.com'}
]

二、C段扫描

2.1 设计思想

1.C段的概念
C段指的是同一内网段内的其他服务器,每个IP有ABCD四个段,举个例子,192.168.0.1,A段就是192,B段是168,C段是0,D段是1,而C段嗅探的意思就是拿下它同一C段中的其中一台服务器,也就是说是D段1-255中的一台服务器,然后利用工具嗅探拿下该服务器。

2.设计思想
首先对传入的IP地址进行 “减D段” 操作,例如传入“192.168.137.129”,经减D操作后得“192.168.137.”,此字符串拼接一个 1~255 之间的数字,得到此IP的整个C段。对 全C段 进行 ping 操作,通过观察返回的TTL得此C段中存活的主机。
此方法还使用了多线程技术,使得扫描速度大大加快。

2.2 代码

import time
from subprocess import Popen, PIPE
import threading

threads = []
thread_max = threading.BoundedSemaphore(255)


# ping检测
def ping_check(ip):
    # ip = '127.0.0.1'
    check = Popen('ping {0}\n'.format(ip), stdin=PIPE, stdout=PIPE, shell=True)
    data = check.stdout.read()
    data = data.decode('GBK')

    if 'TTL' in data:
        print('[+] The host {0} is up'.format(ip))
    # else:
    # print('[+] The host {0} is down'.format(ip))


# 多线程执行
def main(ip):
    for i in range(1, 255):  # 整个D段
        new_ip = ip + str(i)
        thread_max.acquire()
        t = threading.Thread(target=ping_check, args=(new_ip,))
        threads.append(t)
        t.start()
    for t in threads:
        t.join()


if __name__ == '__main__':
    ip = "192.168.137.129"

    # 减D段
    point_number = 0
    figure_number = 0
    for i in ip:
        figure_number += 1
        if i == '.':
            point_number += 1
        if point_number == 3:  # 当遇到第三个.时,进入D段
            cut = len(ip) - figure_number  # 用ip总长度减去A,B,C段长度,即为D段长度
            break

    new_ip = ip[:-cut]
    print(new_ip)

    print('[+] Strat scaning......Please wait...')
    start = time.time()
    main(new_ip)
    end = time.time()
    print("------------耗时{0:.5f}秒------------".format(end - start))

返回结果:

192.168.137.
[+] Strat scaning......Please wait...
[+] The host 192.168.137.2 is up
[+] The host 192.168.137.129 is up
[+] The host 192.168.137.133 is up
------------耗时19.53805秒------------

三、Reference

https://blog.csdn.net/weixin_45605352/article/details/117326120

猜你喜欢

转载自blog.csdn.net/qq_45859826/article/details/124223801
今日推荐