如何使用golang进行tcp syn端口扫描?

问题描述 投票:3回答:1

我正在尝试用golang编写一个tcp syn port扫描程序,我在这里找到了一个C版本的解决方案:http://www.binarytides.com/tcp-syn-portscan-in-c-with-linux-sockets/

我想在go中实现它,如何在golang中发送这样的tcp头:

//TCP Header
    tcph->source = htons ( source_port );
    tcph->dest = htons (80);
    tcph->seq = htonl(1105024978);
    tcph->ack_seq = 0;
    tcph->doff = sizeof(struct tcphdr) / 4;      //Size of tcp header
    tcph->fin=0;
    tcph->syn=1;
    tcph->rst=0;
    tcph->psh=0;
    tcph->ack=0;
    tcph->urg=0;
    tcph->window = htons ( 14600 );  // maximum allowed window size
    tcph->check = 0; //if you set a checksum to zero, your kernel's IP stack should fill in the correct checksum during transmission
    tcph->urg_ptr = 0;

我是否必须使用系统调用或cgo?如果有人可以帮助我,我真的很感激。

sockets tcp go raw-sockets port-scanning
1个回答
0
投票

你将要使用系统调用。但是,syscall包不一定可以跨不同的操作系统移植,因此如果这对您很重要,那么您将不得不编写每个操作系统版本并使用file_os.go命名方案来保存操作系统特定的代码。

© www.soinside.com 2019 - 2024. All rights reserved.