Gopher协议初探

7erry

什么是gopher协议?

Gopher是Internet上一个非常有名的信息查找系统,它将Internet上的文件组织成某种索引,很方便地将用户从Internet的一处带到另一处。在WWW出现之前,Gopher是Internet上最主要的信息检索工具,Gopher站点也是最主要的站点,使用tcp70端口

gopher协议支持发出GET、POST请求:可以先截获get请求包和post请求包,在构成符合gopher协议的请求。gopher协议是ssrf利用中最强大的协议

Gopher协议格式

1
URL:gopher://<host>:<port>/<gopher-path>_TCPDataStream
  • Gopher协议的默认端口为70
  • Gopher协议需要url编码
    • 回车换行 -> %0d%0a
    • ? -> %3f
    • & -> %26
    • TCP数据流的第一个字符不会被接受,所以要加上一个任意字符例如’_’
    • 在HTTP包的最后要加%0d%0a

使用Gopher协议发送HTTP请求

用Gopher协议发送请求可以通过构造一个HTTP包实现,即

  • 构造HTTP报文
  • 将HTTP报文进行URL编码,替换回车换行为%0d%0a
  • 发送Gopher协议

例如

1
2
GET /index.php?name=login HTTP/1.1
Host: 192.168.0.1

URL编码为

1
GET%20/index.php%3fname=login%20HTTP/1.1%0d%0AHost:%20192.168.0.1%0d%0A

最终用Gopher协议发送请求为:

1
gopher://192.168.0.1:80/_GET%20/index.php%3fname=login%20HTTP/1.1%0d%0AHost:%20192.168.0.1%0d%0A

类似的,POST请求就是在报文中加入必要的四个首部行参数和报文体,例如:

1
2
3
4
5
6
POST /index.php HTTP/1.1
host:192.168.0.1
Content-Type:application/x-www-form-urlencoded
Content-Length:10

name=login

编码为:

1
POST%20/index.php%20HTTP/1.1%0d%0AHost:192.168.0.101%0d%0AContent-Type:application/x-www-form-urlencoded%0d%0AContent-Length:10%0d%0A%0d%0Aname=login%0d%0A

使用Gopher协议进行HTTP POST请求:

1
gopher://192.168.0.1:80/_POST%20/index.php%20HTTP/1.1%0d%0AHost:192.168.0.101%0d%0AContent-Type:application/x-www-form-urlencoded%0d%0AContent-Length:10%0d%0A%0d%0Aname=login%0d%0A

利用Gopher协议拓展攻击面

  • 与Redis,MySQL的客户端或者套接字CGI交互实现反弹SHELL并攻击

可以利用Gopherus自动编写语句

  • 使用Gopher协议数据流实现写入操作,例如写入ssh公钥与反弹shell

Reference

https://cloud.tencent.com/developer/article/1587012
https://blog.csdn.net/weixin_50464560/article/details/118425121
https://blog.csdn.net/unexpectedthing/article/details/121667791#gopherFastCGI_99
https://github.com/firebroo/sec_tools/tree/master/redis-over-gopher

  • Title: Gopher协议初探
  • Author: 7erry
  • Created at : 2023-07-01 00:00:00
  • Updated at : 2023-07-01 00:00:00
  • Link: http://7erry.com/2023/07/01/Gopher协议初探/
  • License: This work is licensed under CC BY-NC 4.0.