Building Ncat Portable for Windows
The step by step instructions in this section will guide you through the process of building a portable version of Ncat for the MS Windows platform by means of static linking. The resulted binary, ncat.exe, can then be transported and executed by itself, with no runtime dependencies, across all versions of Microsoft Windows starting from Windows XP to Windows 7.
Before you proceed with building a static version of Ncat, we strongly recommend building a normal, dynamic build of Ncat first, just to get the hang of it or spot building issues that might not pertain to building a static version. Details on how you can achieve that can be found at http://nmap.org/install/.
Now that you've successfully build Ncat with dynamic linking, let's proceed building Ncat Portable for Windows.
First of all, tools of the trade:
- Microsoft Visual C++ 2010
Express Edition is fine: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express
- Latest OpenSSL sources from http://www.openssl.org/source/
Note: Tested with openssl-1.0.0d.
- Perl (needed for building OpenSSl)
Install ActivePerl from activestate.com (free download) http://www.activestate.com/store/activeperl/download/
- Nmap source either from svn or a released version greater then nmap-5.59BETA1
Next step is to build the OpenSSL library you just downloaded statically:
- Extract openssl-x.x.x archive to c:\.
- Create c:\OpenSSL folder for installation.
- Open the Visual Studio 2010 command prompt.
To do this, click Start, point to All Programs, point to Microsoft Visual Studio 2010, point to Visual Studio Tools, and then click Visual Studio 2010 Command Prompt.
- Change directory to the OpenSSL source directory and issue the following commands:
perl Configure --prefix=C:/OpenSSL VC-WIN32 -no-shared
nmake -f ms\nt.mak install
- If all is fine from the above step, copy the resulted static libs and include files from "C:\OpenSSL" to the "mswin32\OpenSSL" directory in the Nmap source tree. Remove the existing include\ and lib\ directories:
c:\OpenSSL\include -> nmap\mswin32\OpenSSL\include
c:\OpenSSL\lib -> nmap\mswin32\OpenSSL\lib
Assuming that everything went fine till now, you're about two steps away from building Ncat portable:
- Open Nmap solution in Visual Studio from mswin32\nmap.sln and switch the build configuration to "Ncat Static" like so:
- Right click on Solution 'nmap' in the Solution Explorer sidebar and choose "Configuration Manager".
- Switch the active solution configuration to "Ncat Static" and then close the Configuration Manager. Make sure that the nsock, nbase and ncat projects have switched to the "Static" configuration also.
- Right click on the ncat project and select "Set as StartUp Project".
- Right click on the "ncat" project in Visual Studio and click "Build". Alternatively you can press the F7 key to start building.
That's it, Ncat should be compiling by now. Wait for the build process to finish and then you can find the resulted Ncat Portable static binary ncat.exe in your nmap directory in ncat\Release. You can take it outside of the build directory and use it as a standalone exe either on your system or any other machine running one of the Microsoft Windows versions supported.
If you're having trouble or questions regarding the steps outlined in this document, feel free to e-mail nmap-dev <at> insecure.org.
If you found this error at compilation:
'openssl/applink.c': No such file or directory
or the resulting exe fails to open sockets:
ncat -l 8000
setsockopt: No error