{"id":16677314,"url":"https://github.com/kernelerr/masscan_windows","last_synced_at":"2026-04-24T15:32:32.684Z","repository":{"id":129726574,"uuid":"221010983","full_name":"KernelErr/masscan_windows","owner":"KernelErr","description":"Masscan for Windows.","archived":false,"fork":false,"pushed_at":"2020-06-08T04:39:41.000Z","size":412,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-29T17:25:08.930Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://bufbuzz.com/zh/%E5%9C%A8Windows-10%E4%B8%8A%E7%BC%96%E8%AF%91Masscan/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KernelErr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-11T15:27:26.000Z","updated_at":"2024-07-31T04:33:49.000Z","dependencies_parsed_at":"2023-08-30T16:24:27.310Z","dependency_job_id":null,"html_url":"https://github.com/KernelErr/masscan_windows","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/KernelErr/masscan_windows","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KernelErr%2Fmasscan_windows","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KernelErr%2Fmasscan_windows/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KernelErr%2Fmasscan_windows/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KernelErr%2Fmasscan_windows/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KernelErr","download_url":"https://codeload.github.com/KernelErr/masscan_windows/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KernelErr%2Fmasscan_windows/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32228975,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T13:25:59.205Z","updated_at":"2026-04-24T15:32:32.651Z","avatar_url":"https://github.com/KernelErr.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MASSCAN: Mass IP port scanner\n\nThis is the fastest Internet port scanner. It can scan the entire Internet\nin under 6 minutes, transmitting 10 million packets per second.\n\nIt produces results similar to `nmap`, the most famous port scanner.\nInternally, it operates more like `scanrand`, `unicornscan`, and `ZMap`, using\nasynchronous transmission. The major difference is that it's faster than these\nother scanners. In addition, it's more flexible, allowing arbitrary address\nranges and port ranges.\n\nNOTE: masscan uses a **custom TCP/IP stack**. Anything other than simple port\nscans will cause conflict with the local TCP/IP stack. This means you need to\neither use the `-S` option to use a separate IP address, or configure your\noperating system to firewall the ports that masscan uses.\n\n# Modified by Kevin Li\nI make it can and only can run on Windows with MinGW. After fixed all bugs, you can really just type `make`.\n\n希望中国的小伙伴们能够关注一下我们的公众号：BufBuzz，谢谢。\n\n# Building\n\nOn Debian/Ubuntu, it goes something like this:\n\n\t$ sudo apt-get install git gcc make libpcap-dev\n\t$ git clone https://github.com/robertdavidgraham/masscan\n\t$ cd masscan\n\t$ make\n\nThis puts the program in the `masscan/bin` subdirectory. You'll have to\nmanually copy it to something like `/usr/local/bin` if you want to\ninstall it elsewhere on the system.\n\nThe source consists of a lot of small files, so building goes a lot faster\nby using the multi-threaded build:\n\n\t$ make -j\n\nWhile Linux is the primary target platform, the code runs well on many other\nsystems. Here's some additional build info:\n* Windows w/ Visual Studio: use the VS10 project\n* Windows w/ MingGW: just type `make`\n* Windows w/ cygwin: won't work\n* Mac OS X /w XCode: use the XCode4 project\n* Mac OS X /w cmdline: just type `make`\n* FreeBSD: type `gmake`\n* other: I don't know, don't care\n\n\n## PF_RING\n\nTo get beyond 2 million packets/second, you need an Intel 10-gbps Ethernet\nadapter and a special driver known as [\"PF_RING ZC\" from ntop](http://www.ntop.org/products/packet-capture/pf_ring/pf_ring-zc-zero-copy/). Masscan doesn't need to be rebuilt in order to use PF_RING. To use PF_RING,\nyou need to build the following components:\n\n* `libpfring.so` (installed in /usr/lib/libpfring.so)\n* `pf_ring.ko` (their kernel driver)\n* `ixgbe.ko` (their version of the Intel 10-gbps Ethernet driver)\n\nYou don't need to build their version of `libpcap.so`.\n\nWhen Masscan detects that an adapter is named something like `zc:enp1s0` instead\nof something like `enp1s0`, it'll automatically switch to PF_RING ZC mode.\n\n## Regression testing\n\nThe project contains a built-in self-test:\n\n\t$ make regress\n\tbin/masscan --regress\n\tselftest: success!\n\nThis tests a lot of tricky bits of the code. You should do this after building.\n\n\n## Performance testing\n\nTo test performance, run something like the following:\n\n\t$ bin/masscan 0.0.0.0/4 -p80 --rate 100000000 --router-mac 66-55-44-33-22-11\n\nThe bogus `--router-mac` keeps packets on the local network segments so that\nthey won't go out to the Internet.\n\nYou can also test in \"offline\" mode, which is how fast the program runs\nwithout the transmit overhead:\n\n\t$ bin/masscan 0.0.0.0/4 -p80 --rate 100000000 --offline\n    \nThis second benchmark shows roughly how fast the program would run if it were\nusing PF_RING, which has near zero overhead.\n\n\n# Usage\n\nUsage is similar to `nmap`. To scan a network segment for some ports:\n\n\t# masscan -p80,8000-8100 10.0.0.0/8\n\nThis will:\n* scan the 10.x.x.x subnet, all 16 million addresses\n* scans port 80 and the range 8000 to 8100, or 102 addresses total\n* print output to `\u003cstdout\u003e` that can be redirected to a file\n\nTo see the complete list of options, use the `--echo` feature. This\ndumps the current configuration and exits. This output can be used as input back\ninto the program:\n\n\t# masscan -p80,8000-8100 10.0.0.0/8 --echo \u003e xxx.conf\n\t# masscan -c xxx.conf --rate 1000\n\n\n## Banner checking\n\nMasscan can do more than just detect whether ports are open. It can also\ncomplete the TCP connection and interaction with the application at that\nport in order to grab simple \"banner\" information.\n\nThe problem with this is that masscan contains its own TCP/IP stack\nseparate from the system you run it on. When the local system receives\na SYN-ACK from the probed target, it responds with a RST packet that kills\nthe connection before masscan can grab the banner.\n\nThe easiest way to prevent this is to assign masscan a separate IP\naddress. This would look like the following:\n\n\t# masscan 10.0.0.0/8 -p80 --banners --source-ip 192.168.1.200\n\nThe address you choose has to be on the local subnet and not otherwise\nbe used by another system.\n\nIn some cases, such as WiFi, this isn't possible. In those cases, you can\nfirewall the port that masscan uses. This prevents the local TCP/IP stack\nfrom seeing the packet, but masscan still sees it since it bypasses the\nlocal stack. For Linux, this would look like:\n\n\t# iptables -A INPUT -p tcp --dport 60000 -j DROP\n\t# masscan 10.0.0.0/8 -p80 --banners --source-port 60000\n\nOn Mac OS X and BSD, it might look like this:\n\n\t# sudo ipfw add 1 deny tcp from any to any 60000 in\n\t# masscan 10.0.0.0/8 -p80 --banners --source-port 60000\n\t\nWindows doesn't respond with RST packets, so neither of these techniques\nare necessary. However, masscan is still designed to work best using its\nown IP address, so you should run that way when possible, even when its\nnot strictly necessary.\n\nThe same thing is needed for other checks, such as the `--heartbleed` check,\nwhich is just a form of banner checking.\n\n\n## How to scan the entire Internet\n\nWhile useful for smaller, internal networks, the program is really designed\nwith the entire Internet in mind. It might look something like this:\n\n\t# masscan 0.0.0.0/0 -p0-65535\n\nScanning the entire Internet is bad. For one thing, parts of the Internet react\nbadly to being scanned. For another thing, some sites track scans and add you\nto a ban list, which will get you firewalled from useful parts of the Internet.\nTherefore, you want to exclude a lot of ranges. To blacklist or exclude ranges,\nyou want to use the following syntax:\n\n\t# masscan 0.0.0.0/0 -p0-65535 --excludefile exclude.txt\n\nThis just prints the results to the command-line. You probably want them\nsaved to a file instead. Therefore, you want something like:\n\n\t# masscan 0.0.0.0/0 -p0-65535 -oX scan.xml\n\nThis saves the results in an XML file, allowing you to easily dump the\nresults in a database or something.\n\nBut, this only goes at the default rate of 100 packets/second, which will\ntake forever to scan the Internet. You need to speed it up as so:\n\n\t# masscan 0.0.0.0/0 -p0-65535 --max-rate 100000\n\nThis increases the rate to 100,000 packets/second, which will scan the\nentire Internet (minus excludes) in about 10 hours per port (or 655,360 hours\nif scanning all ports).\n\nThe thing to notice about this command-line is that these are all `nmap`\ncompatible options. In addition, \"invisible\" options compatible with `nmap`\nare also set for you: `-sS -Pn -n --randomize-hosts --send-eth`. Likewise,\nthe format of the XML file is inspired by `nmap`. There are, of course, a\nlot of differences, because the *asynchronous* nature of the program\nleads to a fundamentally different approach to the problem.\n\nThe above command-line is a bit cumbersome. Instead of putting everything\non the command-line, it can be stored in a file instead. The above settings\nwould look like this:\n\n\t# My Scan\n\trate =  100000.00\n\toutput-format = xml\n\toutput-status = all\n\toutput-filename = scan.xml\n\tports = 0-65535\n\trange = 0.0.0.0-255.255.255.255\n\texcludefile = exclude.txt\n\nTo use this configuration file, use the `-c`:\n\n\t# masscan -c myscan.conf\n\nThis also makes things easier when you repeat a scan.\n\nBy default, masscan first loads the configuration file \n`/etc/masscan/masscan.conf`. Any later configuration parameters override what's\nin this default configuration file. That's where I put my \"excludefile\" \nparameter, so that I don't ever forget it. It just works automatically.\n\n## Getting output\n\nBy default, masscan produces fairly large text files, but it's easy \nto convert them into any other format. There are five supported output formats:\n\n1. xml:  Just use the parameter `-oX \u003cfilename\u003e`. \n\tOr, use the parameters `--output-format xml` and `--output-filename \u003cfilename\u003e`.\n\n2. binary: This is the masscan builtin format. It produces much smaller files, so that\nwhen I scan the Internet my disk doesn't fill up. They need to be parsed,\nthough. The command line option `--readscan` will read binary scan files.\nUsing `--readscan` with the `-oX` option will produce a XML version of the \nresults file.\n\n3. grepable: This is an implementation of the Nmap -oG\noutput that can be easily parsed by command-line tools. Just use the\nparameter `-oG \u003cfilename\u003e`. Or, use the parameters `--output-format grepable` and\n`--output-filename \u003cfilename\u003e`.\n\n4. json: This saves the results in JSON format. Just use the\nparameter `-oJ \u003cfilename\u003e`. Or, use the parameters `--output-format json` and\n`--output-filename \u003cfilename\u003e`.\n\n5. list: This is a simple list with one host and port pair \nper line. Just use the parameter `-oL \u003cfilename\u003e`. Or, use the parameters \n`--output-format list` and `--output-filename \u003cfilename\u003e`. The format is:\n\n\t```\n\t\u003cport state\u003e \u003cprotocol\u003e \u003cport number\u003e \u003cIP address\u003e \u003cPOSIX timestamp\u003e  \n\topen tcp 80 XXX.XXX.XXX.XXX 1390380064\n\t```\t\n\n## Comparison with Nmap\n\nWhere reasonable, every effort has been taken to make the program familiar\nto `nmap` users, even though it's fundamentally different. Two important\ndifferences are:\n\n* no default ports to scan, you must specify `-p \u003cports\u003e`\n* target hosts are IP addresses or simple ranges, not DNS names, nor \n  the funky subnet ranges `nmap` can use (like `10.0.0-255.0-255`).\n\nYou can think of `masscan` as having the following settings permanently\nenabled:\n* `-sS`: this does SYN scan only (currently, will change in the future)\n* `-Pn`: doesn't ping hosts first, which is fundamental to the async operation\n* `-n`: no DNS resolution happens\n* `--randomize-hosts`: scan completely randomized\n* `--send-eth`: sends using raw `libpcap`\n\nIf you want a list of additional `nmap` compatible settings, use the following\ncommand:\n\n\t# masscan --nmap\n\n\n## Transmit rate (IMPORTANT!!)\n\nThis program spews out packets very fast. On Windows, or from VMs,\nit can do 300,000 packets/second. On Linux (no virtualization) it'll\ndo 1.6 million packets-per-second. That's fast enough to melt most networks.\n\nNote that it'll only melt your own network. It randomizes the target\nIP addresses so that it shouldn't overwhelm any distant network.\n\nBy default, the rate is set to 100 packets/second. To increase the rate to\na million use something like `--rate 1000000`.\n\n\n\n# Design\n\nThis section describes the major design issues of the program.\n\n## Code Layout\n\nThe file `main.c` contains the `main()` function, as you'd expect. It also\ncontains the `transmit_thread()` and `receive_thread()` functions. These\nfunctions have been deliberately flattened and heavily commented so that you\ncan read the design of the program simply by stepping line-by-line through\neach of these.\n\n## Asynchronous\n\nThis is an *asynchronous* design. In other words, it is to `nmap` what\nthe `nginx` web-server is to `Apache`. It has separate transmit and receive\nthreads that are largely independent from each other. It's the same sort of\ndesign found in `scanrand`, `unicornscan`, and `ZMap`.\n\nBecause it's asynchronous, it runs as fast as the underlying packet transmit\nallows.\n\n\n## Randomization\n\nA key difference between Masscan and other scanners is the way it randomizes\ntargets.\n\nThe fundamental principle is to have a single index variable that starts at\nzero and is incremented by one for every probe. In C code, this is expressed\nas:\n\n    for (i = 0; i \u003c range; i++) {\n        scan(i);\n    }\n\nWe have to translate the index into an IP address. Let's say that you want to\nscan all \"private\" IP addresses. That would be the table of ranges like:\n    \n    192.168.0.0/16\n    10.0.0.0/8\n    172.16.0.0/12\n\nIn this example, the first 64k indexes are appended to 192.168.x.x to form\nthe target address. Then, the next 16-million are appended to 10.x.x.x.\nThe remaining indexes in the range are applied to 172.16.x.x.\n\nIn this example, we only have three ranges. When scanning the entire Internet,\nwe have in practice more than 100 ranges. That's because you have to blacklist\nor exclude a lot of sub-ranges. This chops up the desired range into hundreds\nof smaller ranges.\n\nThis leads to one of the slowest parts of the code. We transmit 10 million\npackets per second, and have to convert an index variable to an IP address\nfor each and every probe. We solve this by doing a \"binary search\" in a small\namount of memory. At this packet rate, cache efficiencies start to dominate\nover algorithm efficiencies. There are a lot of more efficient techniques in\ntheory, but they all require so much memory as to be slower in practice.\n\nWe call the function that translates from an index into an IP address\nthe `pick()` function. In use, it looks like:\n\n    for (i = 0; i \u003c range; i++) {\n        ip = pick(addresses, i);\n        scan(ip);\n    }\n\nMasscan supports not only IP address ranges, but also port ranges. This means\nwe need to pick from the index variable both an IP address and a port. This\nis fairly straightforward:\n\n    range = ip_count * port_count;\n    for (i = 0; i \u003c range; i++) {\n        ip   = pick(addresses, i / port_count);\n        port = pick(ports,     i % port_count);\n        scan(ip, port);\n    }\n\nThis leads to another expensive part of the code. The division/modulus\ninstructions are around 90 clock cycles, or 30 nanoseconds, on x86 CPUs. When\ntransmitting at a rate of 10 million packets/second, we have only\n100 nanoseconds per packet. I see no way to optimize this any better. Luckily,\nthough, two such operations can be executed simultaneously, so doing two \nof these as shown above is no more expensive than doing one.\n\nThere are actually some easy optimizations for the above performance problems,\nbut they all rely upon `i++`, the fact that the index variable increases one\nby one through the scan. Actually, we need to randomize this variable. We\nneed to randomize the order of IP addresses that we scan or we'll blast the\nheck out of target networks that aren't built for this level of speed. We \nneed to spread our traffic evenly over the target.\n\nThe way we randomize is simply by encrypting the index variable. By definition,\nencryption is random, and creates a 1-to-1 mapping between the original index\nvariable and the output. This means that while we linearly go through the\nrange, the output IP addresses are completely random. In code, this looks like:\n\n    range = ip_count * port_count;\n    for (i = 0; i \u003c range; i++) {\n        x = encrypt(i);\n        ip   = pick(addresses, x / port_count);\n        port = pick(ports,     x % port_count);\n        scan(ip, port);\n    }\n\nThis also has a major cost. Since the range is an unpredictable size instead\nof a nice even power of 2, we can't use cheap binary techniques like\nAND (\u0026) and XOR (^). Instead, we have to use expensive operations like \nMODULUS (%). In my current benchmarks, it's taking 40 nanoseconds to\nencrypt the variable.\n\nThis architecture allows for lots of cool features. For example, it supports\n\"shards\". You can setup 5 machines each doing a fifth of the scan, or\n`range / shard_count`. Shards can be multiple machines, or simply multiple\nnetwork adapters on the same machine, or even (if you want) multiple IP\nsource addresses on the same network adapter.\n\nOr, you can use a 'seed' or 'key' to the encryption function, so that you get\na different order each time you scan, like `x = encrypt(seed, i)`.\n\nWe can also pause the scan by exiting out of the program, and simply\nremembering the current value of `i`, and restart it later. I do that a lot\nduring development. I see something going wrong with my Internet scan, so\nI hit \u003cctrl-c\u003e to stop the scan, then restart it after I've fixed the bug.\n\nAnother feature is retransmits/retries. Packets sometimes get dropped on the\nInternet, so you can send two packets back-to-back. However, something that\ndrops one packet may drop the immediately following packet. Therefore, you\nwant to send the copy about 1 second apart. This is simple. We already have\na 'rate' variable, which is the number of packets-per-second rate we are\ntransmitting at, so the retransmit function is simply to use `i + rate`\nas the index. One of these days I'm going to do a study of the Internet,\nand differentiate \"back-to-back\", \"1 second\", \"10 second\", and \"1 minute\"\nretransmits this way in order to see if there is any difference in what\ngets dropped.\n\n\n\n## C10 Scalability\n\nThe asynchronous technique is known as a solution to the \"c10k problem\".\nMasscan is designed for the next level of scalability, the \"C10M problem\".\n\nThe C10M solution is to bypass the kernel. There are three primary kernel\nbypasses in Masscan:\n* custom network driver\n* user-mode TCP stack\n* user-mode synchronization\n\nMasscan can use the PF_RING DNA driver. This driver DMAs packets directly\nfrom user-mode memory to the network driver with zero kernel involvement.\nThat allows software, even with a slow CPU, to transmit packets at the maximum\nrate the hardware allows. If you put 8 10-gbps network cards in a computer,\nthis means it could transmit at 100-million packets/second.\n\nMasscan has its own built-in TCP stack for grabbing banners from TCP\nconnections. This means it can easily support 10 million concurrent TCP\nconnections, assuming of course that the computer has enough memory.\n\nMasscan has no \"mutex\". Modern mutexes (aka. futexes) are mostly user-mode,\nbut they have two problems. The first problem is that they cause cache-lines\nto bounce quickly back-and-forth between CPUs. The second is that when there\nis contention, they'll do a system call into the kernel, which kills\nperformance. Mutexes on the fast path of a program severely limits scalability.\nInstead, Masscan uses \"rings\" to synchronize things, such as when the\nuser-mode TCP stack in the receive thread needs to transmit a packet without\ninterfering with the transmit thread.\n\n\n## Portability\n\nThe code runs well on Linux, Windows, and Mac OS X. All the important bits are\nin standard C (C90). It therefore compiles on Visual Studio with Microsoft's\ncompiler, the Clang/LLVM compiler on Mac OS X, and GCC on Linux.\n\nWindows and Macs aren't tuned for packet transmit, and get only about 300,000\npackets-per-second, whereas Linux can do 1,500,000 packets/second. That's\nprobably faster than you want anyway.\n\n\n## Safe code\n\nA bounty is offered for vulnerabilities, see the VULNINFO.md file for more\ninformation.\n\nThis project uses safe functions like `strcpy_s()` instead of unsafe functions\nlike `strcpy()`.\n\nThis project has automated unit regression tests (`make regress`).\n\n\n## Compatibility\n\nA lot of effort has gone into making the input/output look like `nmap`, which\neveryone who does port scans is (or should be) familiar with.\n\n\n# Authors\n\nThis tool created by Robert Graham:\nemail: robert_david_graham@yahoo.com\ntwitter: @ErrataRob\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkernelerr%2Fmasscan_windows","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkernelerr%2Fmasscan_windows","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkernelerr%2Fmasscan_windows/lists"}