Skip to content

Commit c517ded

Browse files
authored
Merge pull request #7 from jhart-r7/pr/9079-gopher
Gopher improvements
2 parents 297ca25 + f938a10 commit c517ded

File tree

2 files changed

+108
-54
lines changed

2 files changed

+108
-54
lines changed

documentation/modules/auxiliary/scanner/gopher/gopher_gophermap.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,42 @@
33
Any gopher server will work. There seems to only be [a few left](https://en.wikipedia.org/wiki/Gopher_(protocol)#Server_software)
44
in 2017.
55

6+
A few options for local installation and testing are below.
7+
8+
### Docker Install
9+
10+
A [dockerized gopher server written in Go](https://hub.docker.com/r/prodhe/gopher/) is available. To install and run this, with content being
11+
served out of a temporary directory in which you'll be left:
12+
13+
```
14+
$ docker pull prodhe/gopher
15+
Using default tag: latest
16+
latest: Pulling from prodhe/gopher
17+
627beaf3eaaf: Already exists
18+
8800e3417eb1: Pull complete
19+
d9f3bcdad0eb: Pull complete
20+
c018073abd26: Pull complete
21+
b2855f535c50: Pull complete
22+
23480a2f73d8: Pull complete
23+
1555a5435ec5: Pull complete
24+
0728d289e0fc: Pull complete
25+
6f6f265b58ee: Pull complete
26+
Digest: sha256:69931d56946d192d9bd155a88b6f365cb276e9edf453129d374e64d244d1edaa
27+
Status: Downloaded newer image for prodhe/gopher:latest
28+
$ cd `mktemp -d`;
29+
$ sudo docker run --rm -d -it --name gopher_test -v `pwd -P`:/public -p 70:70 prodhe/gopher
30+
2017/10/20 16:45:01 Serving /public/ at localhost:70
31+
$ date > test.txt
32+
$ echo HELLO > README.md
33+
```
34+
35+
*NOTE*: Don't forget to `docker stop` the container ID returned from the `docker run` command just run above:
36+
```
37+
$ docker stop X
38+
X
39+
```
40+
41+
642
### Ubuntu 16.04 Install
743

844
First we need to install the server:
@@ -67,23 +103,37 @@ The following table contains the file types associated with the characters:
67103

68104
**PATH**
69105

70-
It is possible to view content within a directory of the gophermap. If the intial run shows directory `Directory: foobar`,
106+
It is possible to view content within a directory of the gophermap. If the intial run shows directory `Directory: foobar`,
71107
setting **path** to `/foobar` will enumerate the contents of that folder. Default: [empty string].
72108

73109
## Scenarios
74110

111+
### Docker Gopher Server
112+
```
113+
msf > use auxiliary/scanner/gopher/gopher_gophermap
114+
msf auxiliary(gopher_gophermap) > set RHOSTS localhost
115+
RHOSTS => localhost
116+
msf auxiliary(gopher_gophermap) > run
117+
118+
[+] 127.0.0.1:70 - Text file: README.md
119+
[+] 127.0.0.1:70 - Path: localhost:70/README.md
120+
[+] 127.0.0.1:70 - Text file: test.txt
121+
[+] 127.0.0.1:70 - Path: localhost:70/test.txt
122+
[*] Scanned 1 of 1 hosts (100% complete)
123+
[*] Auxiliary module execution completed
124+
```
75125
### Gopher-server on Ubuntu 16.04
76126

77127
```
78-
msf > use auxiliary/scanner/gopher/gopher_gophermap
128+
msf > use auxiliary/scanner/gopher/gopher_gophermap
79129
msf auxiliary(gopher_gophermap) > set rhosts 1.1.1.1
80130
rhosts => 1.1.1.1
81131
msf auxiliary(gopher_gophermap) > set verbose true
82132
verbose => true
83133
msf auxiliary(gopher_gophermap) > run
84134
85135
[+] 1.1.1.1:70 - gopher custom gophermap
86-
[+] 1.1.1.1:70 -
136+
[+] 1.1.1.1:70 -
87137
[+] 1.1.1.1:70 - HTML: Hello World
88138
[+] 1.1.1.1:70 - Path: 1.1.1.1:70/example.html
89139
[+] 1.1.1.1:70 - Text file: Foo File

modules/auxiliary/scanner/gopher/gopher_gophermap.rb

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,50 @@ class MetasploitModule < Msf::Auxiliary
1111
def initialize
1212
super(
1313
'Name' => 'Gopher gophermap Scanner',
14-
'Description' => %q{
14+
'Description' => %q(
1515
This module identifies Gopher servers, and processes the gophermap
1616
file which lists all the files on the server.
17-
},
17+
),
1818
'References' =>
1919
[
20-
['URL', 'https://sdfeu.org/w/tutorials:gopher'],
20+
['URL', 'https://sdfeu.org/w/tutorials:gopher']
2121
],
2222
'Author' => 'h00die',
2323
'License' => MSF_LICENSE
2424
)
2525

26-
register_options([
27-
Opt::RPORT(70),
28-
OptString.new('PATH',[false,'Path to enumerate',''])
29-
])
30-
26+
register_options(
27+
[
28+
Opt::RPORT(70),
29+
OptString.new('PATH', [false, 'Path to enumerate', ''])
30+
]
31+
)
3132
end
3233

34+
TYPE_MAP = {
35+
'0' => 'Text file',
36+
'1' => 'Directory',
37+
'2' => 'CSO name server',
38+
'3' => 'Error',
39+
'4' => 'Mac HQX filer',
40+
'5' => 'PC binary',
41+
'6' => 'UNIX uuencoded file',
42+
'7' => 'Search server',
43+
'8' => 'Telnet Session',
44+
'9' => 'Binary File',
45+
'c' => 'Calendar',
46+
'e' => 'Event',
47+
'g' => 'GIF image',
48+
'h' => 'HTML',
49+
'i' => 'inline text',
50+
's' => 'Sound',
51+
'I' => 'Image',
52+
'M' => 'MIME multipart/mixed message',
53+
'T' => 'TN3270 Session'
54+
}.freeze
55+
3356
def get_type(char)
34-
return {'0' => 'Text file',
35-
'1' => 'Directory',
36-
'2' => 'CSO name server',
37-
'3' => 'Error',
38-
'4' => 'Mac HQX filer',
39-
'5' => 'PC binary',
40-
'6' => 'UNIX uuencoded file',
41-
'7' => 'Search server',
42-
'8' => 'Telnet Session',
43-
'9' => 'Binary File',
44-
'c' => 'Calendar',
45-
'e' => 'Event',
46-
'g' => 'GIF image',
47-
'h' => 'HTML',
48-
'i' => 'inline text',
49-
's' => 'Sound',
50-
'I' => 'Image',
51-
'M' => 'MIME multipart/mixed message',
52-
'T' => 'TN3270 Session'}.fetch(char.chomp)
57+
TYPE_MAP.fetch(char.chomp)
5358
end
5459

5560
def run_host(ip)
@@ -59,32 +64,32 @@ def run_host(ip)
5964
gophermap = sock.get_once
6065
if gophermap
6166
gophermap.split("\r\n").each do |line|
62-
if line.split("\t").length >= 2
63-
# syntax: [type_character]description[tab]path[tab, after this is optional]server[tab]port
64-
line = line.split("\t")
65-
desc = line[0]
66-
type_char = desc.slice!(0) #remove first character which is the file type
67-
file_type = get_type(type_char)
68-
if file_type && file_type == 'inline text'
69-
print_good(desc)
70-
next
71-
end
72-
if file_type
73-
print_good(" #{file_type}: #{desc}")
74-
else
75-
print_good(" Invalid File Type (#{type_char}): #{desc}")
76-
end
77-
if line.length >= 3
78-
print_good(" Path: #{line[2]}:#{line[3]}#{line[1]}")
79-
elsif line.length >= 2
80-
print_good(" Path: #{line[2]}#{line[1]}")
81-
else
82-
print_good(" Path: #{line[1]}")
67+
line_parts = line.split("\t")
68+
next unless line_parts.length >= 2
69+
# syntax: [type_character]description[tab]path[tab, after this is optional]server[tab]port
70+
line_parts = line.split("\t")
71+
desc = line_parts[0]
72+
type_char = desc.slice!(0) # remove first character which is the file type
73+
file_type = get_type(type_char)
74+
if file_type && file_type == 'inline text'
75+
print_good(desc)
76+
next
77+
end
78+
if file_type
79+
print_good(" #{file_type}: #{desc}")
80+
else
81+
print_good(" Invalid File Type (#{type_char}): #{desc}")
82+
end
83+
if line_parts.length >= 3
84+
print_good(" Path: #{line_parts[2]}:#{line_parts[3]}#{line_parts[1]}")
85+
elsif line.length >= 2
86+
print_good(" Path: #{line_parts[2]}#{line_parts[1]}")
87+
else
88+
print_good(" Path: #{line_parts[1]}")
8389

84-
end
8590
end
8691
end
87-
report_service(:host => ip, :port => rport, :name => 'gopher', :info => gophermap)
92+
report_service(host: ip, port: rport, service: 'gopher', info: gophermap)
8893
else
8994
print_error('No gophermap')
9095
end
@@ -95,5 +100,4 @@ def run_host(ip)
95100
disconnect
96101
end
97102
end
98-
99103
end

0 commit comments

Comments
 (0)