I've seen a few posts on methods of securing a netcat shell, but i noticed they all fail due to the universal pwd "*" working (due to the .bat approach).
So instead i knocked up a couple of lines of c code.
Here's the code:
// ncAuthenticate.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
int main(int argc, char* argv[]) {
char myPwd[20];
cout << "Welcome to NetCat shell"; // best to leave this out for stealth reasons cin >> myPwd;
To connect to the shell type nc -v -n ipaddresss 7337.
This post is to demonstrate the use of netcat to provide secure shells - e.g. to connect to your home pc from work, it's not intended for illegal use and I accept no responsibility for such acts.
Enjoy...
pollux
Jun 2 2004, 07:36 AM
ThX man i will test this )
freeman
Jun 2 2004, 11:33 AM
have you forgotten to attach the file or you just want us to compile using the modified code?
tibbar
Jun 2 2004, 05:40 PM
just make yourself a hello world wizzard app in vc++ and paste the code in. i prefer not to post compiled files, as the AV firms will just make your life hell otherwise.
UnDeRTaKeR
Jun 4 2004, 01:18 PM
can you post stdafx.h?
clip
Jun 4 2004, 05:19 PM
you dont need stdafx to compile it's just some lame microsoft thing.
you probaly need to include io.h though.
erm, edit2.. I'm not very fammiliar with "cin" but wouldent input of more than 20 charachers cause a buffer overflow?
clip
Jun 4 2004, 05:34 PM
just in case here is a C version that i know is safe: Edit: Version 2
CODE
// Safe C version of NCAUTH // use like this: // nc.exe -L -p 9999 -e ncauth.exe
#include "stdio.h" #include "stdlib.h"
#define PASSWORD "test"
int main(){ char myPwd[20]; unsigned int i; fgets(myPwd,sizeof(myPwd),stdin); for (i = 0; i < strlen(myPwd); i++) if (myPwd[i]=='\r'||myPwd[i]=='\n') myPwd[i]='\0'; if( strcmp(myPwd,PASSWORD) == 0 ) { system("cmd.exe"); } return 0; }
saetji
Jun 13 2004, 05:38 PM
problem with 2nd code: if no pass is entered, it foesn't work if u connect again
ShadowRun
Jun 13 2004, 06:41 PM
than you may add infinite loop and check password's in it
it's only my opinion i may be wrong
greetz
ps. generally you could make sth like this on your own or modify one of posted here
clip
Jun 13 2004, 08:51 PM
QUOTE (saetji @ Jun 13 2004, 05:38 PM)
problem with 2nd code: if no pass is entered, it foesn't work if u connect again
you need to use the -L (upper case L) instead of -l
saetji
Jun 14 2004, 10:01 AM
clip: did u even try it? I AM talking about when -L is used (as opposed to -l)
If u enter a right pass - works fine and gives u shell Connect again and enter wrong pass - doesn't give u anything Connect again - enter NO pass and press CTRL-C to force a close (to simulate a port scan) and try connecting again, and u cant
tibbar
Jun 16 2004, 06:52 PM
hmm you need both -l and -L. With these options i have tried to get it to stop connecting via the method you described and it kept working.
the buffer overflow risk is clearly there in the rough code i posted, search msdn for safer method of input, or just stick a try catch around it to avoid the crash.
bjoernfun
Jun 24 2004, 11:03 AM
thanks for the coding!
into the clip version you must include string.h!
vnet576
Jun 24 2004, 07:21 PM
The problem of reconnecting can be easily solved. Netcat goes into an infinite loop by default I believe when it is listening. All you have to do is recv() for data. If data recieved is greater than 0 launch u're password checker. This is basically the technique that I use for my bind shell program, it should give u an idea on how its done.
One more thing its always a bad idea to use a plaintext password. Use an encryption method to encrypt the password inside netcat. That way some smart ass with a hex editor won't be able to get the password.
vnet - very true about encryption, but remember i am using this for my home pc for remote axxs from work, so only i would have the source.
but for the kiddies, use a decent hash algorithm.
Kynroxes
Jun 30 2004, 08:19 AM
Becareful about buffer overflow on your code, you must to check the size of password during the authenticating. However, if the size of required password is defined, caution to the brute force attack ...
saetji
Sep 18 2004, 05:07 PM
Would anyone mind incorporating both those last ideas (size of pass and bypassing the infinite loop) into a code ... id do it but i sux at programming :\
alpha|beta
Sep 20 2004, 02:47 PM
There is no need to reinvent the wheel. Cryptcat has always been out there, i see no reason in trying to add "authentication" to Netcat.
Gotisch
Sep 20 2004, 08:41 PM
actually thats not only for netcat, afaik you could use that for anything and include it in multiple applications.
And that argument about reinventing the wheel is just a bit short-sighted if you ask me.
clip
Sep 23 2004, 07:10 AM
I think this fixes the loop problem. NC only goes back to listening if the child process returns <> 0. Might be wrong though. This code is safe from buffer overflow. fgets limits the amount of bytes read from the stdin stream to 127bytes one less than the size if the myPwd[] buffer.
CODE
// Safe C version of NCAUTH v.2 // use like this: // nc.exe -L -p 9999 -e ncauth.exe
#include "stdio.h" #include "stdlib.h"
#define PASSWORD "test"
int main(){ char myPwd[128]; memset(&myPwd, '\0', sizeof(myPwd)); unsigned int i; fgets(myPwd,sizeof(myPwd)-1,stdin); // No overflow for (i = 0; i < strlen(myPwd); i++) if (myPwd[i]=='\r'||myPwd[i]=='\n') myPwd[i]='\0'; if( strcmp(myPwd,PASSWORD) == 0 ) { system("@CMD"); } return 1; }
alpha|beta
Sep 25 2004, 09:59 PM
QUOTE (Gotisch @ Sep 20 2004, 08:41 PM)
actually thats not only for netcat, afaik you could use that for anything and include it in multiple applications.
And that argument about reinventing the wheel is just a bit short-sighted if you ask me.
You have a valid point there, at your second sentence. But the author did not advertise the fact that he was implementing a generic authentication mechanism. Even his projec t is named "NCAUTH".
Cheers for the code snippet though.
tibbar
Sep 25 2004, 10:35 PM
to be honest i didnt think about this much originally. i just saw ppl using batch files with netcat that would also accept * as a password! So i thought id draw up some rough code to illustrate how it could be done more securely.
- This .bat can be used with netcat (it is what i use). It does not work if you enter "*" for the password. It reads from config.dat, which is just a text file in the form of:
CODE
pass: yourpwhere
-Ass for encryption i would have no idea how to do that with a .bat file. However the people stupid enough to have netcat running on there comp as a backdoor would never notice my password file or think to open it. Also instead of reading from config.dat you can just make the pw set. I use the config.dat so i can change the pw at any time. Hope this helps
Gotisch
Sep 26 2004, 05:08 PM
tstngry actually that batch is really not very hard to crack running nc with nc -L -p 8666 -vv -e yourbat.bat
CODE
C:\>nc 127.0.0.1 8666 ♀Das System kann die angegebene Datei nicht finden. ♀