4

I am learning to use Golang to develop hacking tools through Blackhat-Go and port scan scanme.nmap.org on Windows and Linux while doing TCP scanning.Here's my code

package main

import (
    "fmt"
    "net"
    "sort"
)

func worker(ports, result chan int) {
    for port := range ports {
        address := fmt.Sprintf("scanme.nmap.org:%d", port)
        conn, err := net.Dial("tcp", address)
        if err != nil {
            result <- 0
            continue
        }
        conn.Close()
        result <- port
    }
}

func main() {
    ports := make(chan int, 100)
    result := make(chan int)
    var openport []int

    for i := 0; i < cap(ports); i++ {
        go worker(ports, result)
    }

    go func() {
        for i := 0; i < 1024; i++ {
            ports <- i
        }
    }()

    for i := 0; i < 1024; i++ {
        port := <-result
        if port != 0 {
            openport = append(openport, port)
        }
    }

    close(ports)
    close(result)
    sort.Ints(openport)

    for _, value := range openport {
        fmt.Printf("%d open\n", value)
    }
}

Running on Windows shows that port 25 is open.

22 open
25 open 
80 open 
110 open

However, port 25 is not detected on Linux.

22 open
80 open 
110 open

I used NMAP to scan and found that the state of port 25 is Filtered.

25/tcp filtered smtp

Why is port 25 detected on Windows.

any help please.

L2ksy0d
  • 83
  • 4
  • Is it detected as open when you run it from the windows machine itself? – zerkms Jul 31 '22 at 02:32
  • When I use net. Dial to connect on Windows, err's value is nil – L2ksy0d Jul 31 '22 at 02:51
  • Is it detected as open when you run it from the windows machine itself? – zerkms Jul 31 '22 at 22:30
  • yes,I use net.Dial to make a TCP connection and determine if the return value is nil. When I run it on a Windows PC, it shows port 25 open @zerkms – L2ksy0d Aug 01 '22 at 01:58
  • I'm guessing this is not due to go at all, since nmap agrees. You should ask on super user or server fault. Especially if windows nmap behaves like windows go, because then your program is out of the equation – erik258 Aug 01 '22 at 02:03
  • @L2ksy0d so, what if it's open for local connections only? What actually is a problem? It's not a surprise that sometimes ports are open from one host and not open for another host :shrug: – zerkms Aug 01 '22 at 22:13
  • @L2ksy0d : if you still have the issue today, perhaps check what error is returned ? – LeGEC Oct 31 '22 at 20:31

0 Answers0