首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在iptables中打开端口

在iptables中打开端口
EN

Unix & Linux用户
提问于 2018-05-23 00:19:57
回答 1查看 8.3K关注 0票数 -1

我尝试iptables -I INPUT -p tcp -m tcp --dport 4444 -j ACCEPT打开一个端口,但仍然关闭:

代码语言:javascript
复制
$ nmap hostname -p 4444
Starting Nmap 7.70 ( https://nmap.org ) at 2018-05-23 04:47 +0430
Nmap scan report for linux (127.0.1.1)
Host is up (0.000040s latency).
rDNS record for 127.0.1.1: Linux.domain.linux

PORT     STATE  SERVICE
4444/tcp closed krb524

Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds

可能是什么原因?我该怎么办呢?

EN

回答 1

Unix & Linux用户

发布于 2018-05-23 01:34:20

必须有监听端口的东西,单独打开防火墙并不能打开它。

这里httpd正在监听80,所以它显示为打开。

代码语言:javascript
复制
$ nmap localhost -p 80

Starting Nmap 6.40 ( http://nmap.org ) at 2018-05-22 19:22 MDT
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00019s latency).
Other addresses for localhost (not scanned): 127.0.0.1
PORT   STATE SERVICE
80/tcp open  http

Nmap done: 1 IP address (1 host up) scanned in 0.18 seconds

这里netstat显示我正在监听80,因为httpd正在监听它。

代码语言:javascript
复制
$ netstat --listening --numeric-ports | grep 80
tcp6       0      0 [::]:80                 [::]:*                  LISTEN

$ systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2018-05-22 18:18:01 MDT; 1h 5min ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 1279 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
    Tasks: 7
   CGroup: /system.slice/httpd.service
           ├─1279 /usr/sbin/httpd -DFOREGROUND
           ├─1928 /usr/sbin/httpd -DFOREGROUND
           ├─1929 /usr/sbin/httpd -DFOREGROUND
           ├─1930 /usr/sbin/httpd -DFOREGROUND
           ├─1931 /usr/sbin/httpd -DFOREGROUND
           ├─1932 /usr/sbin/httpd -DFOREGROUND
           └─1933 /usr/sbin/httpd -DFOREGROUND

May 22 18:17:55 trogdor.mydomain.com systemd[1]: Starting The Apache HTT...
May 22 18:18:01 trogdor.mydomain.com systemd[1]: Started The Apache HTTP...
Hint: Some lines were ellipsized, use -l to show in full.

如果我关闭httpd:

代码语言:javascript
复制
# systemctl stop httpd 
$ nmap localhost -p 80

Starting Nmap 6.40 ( http://nmap.org ) at 2018-05-22 19:23 MDT
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00017s latency).
Other addresses for localhost (not scanned): 127.0.0.1
PORT   STATE  SERVICE
80/tcp closed http

Nmap done: 1 IP address (1 host up) scanned in 0.13 seconds

Netstat显示我没有收听80,尽管它是开放的

代码语言:javascript
复制
$ netstat --listening --numeric-ports | grep 80
$ 

关键是,IPTables部分是一个XyProblem。如果我在4444上启动反向连接侦听器(这是从rapid7 7问答中获取的),那么端口4444显示为打开和侦听,并且我从来不需要触摸IP表。

代码语言:javascript
复制
msf > use exploit/multi/handler
msf exploit(handler) > set PAYLOAD windows/meterpreter/reverse_tcp
msf exploit(handler) > set LHOST 127.0.0.1
msf exploit(handler) > set LPORT 4444
msf exploit(handler) > set ExitOnSession false
msf exploit(handler) > exploit -j

# netstat --numeric-ports --listening | grep 4444
tcp        0      0 localhost:4444          0.0.0.0:* 
票数 2
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/445444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档