Skip to content

Commit

Permalink
feat: http proto (beta)
Browse files Browse the repository at this point in the history
  • Loading branch information
fagci committed Apr 9, 2022
1 parent 5e75cff commit 68f8791
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ Scan list of networks and hosts:
cat city_cidrs.txt | ./gons -s rtsp -list -
```

Search for public resources over http:

```sh
./gons -s http -d ./assets/data/http-pub-paths.txt -rb "Index of"
```

Search for public mjpeg webcams:

```sh
./gons -s http -d ./assets/data/http-cam-paths.txt -i tun0 -rh "(image/jpeg|multipart/x-mixed-replace)"
```

## Testing

```sh
Expand Down
2 changes: 2 additions & 0 deletions assets/data/http-cam-paths.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/-wvhttp-01-/image.cgi?v=jpg:640x480
/nphMotionJpeg?Resolution=640x480&Quality=Standard
/mjpg/video.mjpg
6 changes: 6 additions & 0 deletions assets/data/http-pub-paths.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/content/uploads
/files
/public
/upload
/uploads
/wp-content/uploads
38 changes: 18 additions & 20 deletions services/http.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package services

import (
"bufio"
"crypto/tls"
"io"
"net"
"net/http"
"net/textproto"
"net/url"
"regexp"
"strings"
Expand Down Expand Up @@ -66,38 +65,37 @@ func (s *HTTPService) check(uri url.URL) bool {
if err != nil {
return false
}

isText := false
defer r.Body.Close()
defer c.CloseIdleConnections()

if r.StatusCode > 400 {
return false
}

for k, values := range r.Header {
for _, v := range values {
if k == "Content-Type" && strings.Contains(v, "text/") {
isText = true
}
if s.headerReg != nil && s.headerReg.MatchString(v) {
if s.headerReg != nil && s.headerReg.MatchString(k+": "+v) {
return true
}
}
}

if !isText {
if r.ContentLength == -1 || r.ContentLength > 1024*1024 {
return false
}

reader := bufio.NewReader(r.Body)
tr := textproto.NewReader(reader)
for {
line, err := tr.ReadLine()
if err != nil {
break
}
if s.bodyReg != nil && s.bodyReg.MatchString(line) {
return true
}
reader := io.LimitReader(r.Body, 1024*1024)
b, err := io.ReadAll(reader)

if err != nil {
return false
}

if s.bodyReg != nil && s.bodyReg.Match(b) {
return true
}

if s.headerReg == nil && s.bodyReg == nil && r.StatusCode < 400 {
if s.headerReg == nil && s.bodyReg == nil {
return true
}

Expand Down

0 comments on commit 68f8791

Please sign in to comment.