Quickly scan a machine via squid, adjust source to change ips, ports etc. This is just a quick and dirty poc but it's way faster than nmap.
-
-
Save xct/597d48456214b15108b2817660fdee00 to your computer and use it in GitHub Desktop.
squidscan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module squidscan | |
go 1.16 | |
require github.com/cheggaaa/pb/v3 v3.1.2 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net" | |
"net/http" | |
"net/url" | |
"sync" | |
"time" | |
"strings" | |
"io/ioutil" | |
"github.com/cheggaaa/pb/v3" | |
) | |
var ( | |
proxyURL = "http://127.0.0.1:8080" // adjust proxy ip & port | |
numWorkers = 100 // adjust workers | |
numPorts = 65535 // adjust ports | |
) | |
func main() { | |
proxyURL, err := url.Parse(proxyURL) | |
if err != nil { | |
fmt.Printf("Failed to parse proxy URL: %v\n", err) | |
return | |
} | |
transport := &http.Transport{ | |
Proxy: http.ProxyURL(proxyURL), | |
DialContext: (&net.Dialer{ | |
Timeout: 3 * time.Second, | |
KeepAlive: 3 * time.Second, | |
}).DialContext, | |
} | |
client := &http.Client{Transport: transport} | |
openPorts := make([]int, 0) | |
bar := pb.StartNew(numPorts) | |
sem := make(chan struct{}, numWorkers) | |
var wg sync.WaitGroup | |
for port := 1; port <= numPorts; port++ { | |
wg.Add(1) | |
go func(p int) { | |
defer wg.Done() | |
sem <- struct{}{} | |
defer func() { | |
<-sem | |
bar.Increment() | |
}() | |
address := fmt.Sprintf("127.0.0.1:%d", p) | |
r, err := client.Get(fmt.Sprintf("http://%s", address)) | |
if err != nil { | |
return | |
} | |
data, _ := ioutil.ReadAll(r.Body) | |
dataStr := string(data) | |
if strings.Contains(dataStr,"The requested URL could not be retrieved"){ | |
return; | |
} | |
defer r.Body.Close() | |
openPorts = append(openPorts, p) | |
fmt.Printf("Port %d found!\n", p) | |
}(port) | |
} | |
wg.Wait() | |
bar.Finish() | |
fmt.Println("Open ports:") | |
for _, port := range openPorts { | |
fmt.Println(port) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment