NetCat – Visual Studio – Source Code Compilation

Background

Wanted to use netcat (nc) on MS Windows.

What is NetCat ?

Wikipedia

Link

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

  1. eternallybored.org
    • netcat
      • Documentation
      • Source Code

Compilation

Here is a sample compilation code for Microsoft Visual Studio.Net.

Link


 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

  1. The error is due to the location of the sys/time.h file in Microsoft Visual Studio
  2. The code is looking for it it as sys/time.h.
  3. Whereas it is not in sys subfolder

Referencing Code

time.h.01.20200125.0722PM

Remediation

  1. Add #define WIN32
  2. Defining WIN32 will have 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

One thought on “NetCat – Visual Studio – Source Code Compilation

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s