Background
Wanted to use netcat (nc) on MS Windows.
What is NetCat ?
Wikipedia
netcat is a computer networking utility for reading from and writing to network connections using TCP or UDP. The command is designed to be a dependable back-end that can be used directly or easily driven by other programs and scripts.
Function: Arbitrary TCP and UDP connections and listens.
AntiVirus
Unfortunately, Anti-Virus (AV ) tools routinely block its use.
A sufficient workaround is to download the source code and recompile the source code and generate a new executable.
Artifacts
Compilation
Here is a sample compilation code for Microsoft Visual Studio.Net.
setlocal set "_compilerFolder=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\" set "_compilerBinary=cl.exe" set "_sourceCodeFolder=." set "_app=nc" set "_base=netcat" set "_option=getopt" set "_exec=doexec" set "_sourceCodeFile_01=%_base%.c" set "_sourceCodeFile_02=%_option%.c" set "_sourceCodeFile_03=%_exec%.c" set "_outputFile=%_app%.exe" set "_DEBUG=/DEBUG:FULL /Z7" rem set "_DEBUG=/Z7" set "_compilerFlag=%_DEBUG%" "%_compilerFolder%\%_compilerBinary%" %_sourceCodeFolder%\%_sourceCodeFile_01% ^ %_sourceCodeFolder%\%_sourceCodeFile_02% ^ %_sourceCodeFolder%\%_sourceCodeFile_03% ^ /Fe:%_outputFile% %_compilerFlag% endlocal
Source Code Changes
Error
Error – 1 – fatal error C1083: Cannot open include file: ‘sys/time.h’: No such file or directory
Outline
- The error is due to the location of the time.h file in Microsoft Visual Studio
- The code is looking for time.h in the sys sub-folder ( sys/time.h ).
- Whereas it is not in the sys sub-folder
Referencing Code
Remediation
- Add #define WIN32
- Defining WIN32 will have the compiler look for time.h in the root header folder and not under under the sys sub-folder
Source Code
GitHub
DanielAdeniji/Netcat-nc-OnMSWindows
Link
References
- Docs \ Microsoft C++, C, and Assembler \ Errors and warnings \ Compiler fatal errors
- Fatal error C1083
Link
- Fatal error C1083
[…] NetCat – Visual Studio – Source Code Compilation Link […]
[…] NetCat – Visual Studio – Source Code Compilation Link […]
[…] NetCat – Visual Studio – Source Code Compilation Link […]