Shell GPT (SGPT) is a command-line tool that integrates with OpenAI’s GPT-4 models to enable natural language processing (NLP) from your Linux shell. It’s designed to simplify repetitive tasks, generate scripts, and assist with coding, all from within the terminal environment. SGPT is a powerful tool that brings the capabilities of OpenAI’s GPT models directly into the Linux command line.
SGPT itself is free to install and use, but you will need an OpenAI API key, which may come with costs depending on your usage tier. SGPT requires an active internet connection as it relies on OpenAI’s cloud-based API to function.
Â
Requirements
- Python Version: Python 3.6 or later
- OpenAI API Key: You will need an API key from OpenAI to access GPT models.
Install SGPT
Step 1: Install Python
SGPT requires Python to run. Most Linux distributions come with Python pre-installed, but if not, you can install it using:sudo apt install python3
Step 2: Install pip (Python Package Installer)
You’ll need a pip to install SGPT. Install it using the following command:sudo apt install python3-pip
Step 3: Install SGPT
Now that Python and pip are installed, you can install SGPT using pip:pip install shell-gpt --break-system-packages
note: you will need to add --break-system-packages at the end of command. Else, you will get some warning messages and installation will be stopped.Â
Step 4: Verify Installation
Once the installation is complete, verify that SGPT has been installed correctly by running:┌──(root㉿kali)-[~/.config/shell_gpt]
└─# sgpt --version
ShellGPT 1.4.4
This should ask you to enter openai api key, then return the installed version of SGPT, confirming that it’s ready for use.
Setting up OpenAI API Key
ÂStep 1: Get the OpenAI API Key
- Go to the OpenAI API website.
- Sign up or log in to your account.
- Navigate to the API section and generate a new API key.
Usage:
Step 2: Set API Key in Environment Variables
zsh and bash are different shells that can be used on macOS and other Unix style OSes (Linux, BSD, macOS …). zsh is similar to bash but has some additional features.Âzsh is the default shell in more recent macOS versions while bash is the default for older ones. You can change what shell gets used when you open an new tab or window in Terminal by going to the Terminal preferences. Both zsh and bash have a number of different shell files that get run at different times. The one you want to edit is either .zshrc or .bashrc (depending on your choice of shell) - these specific files contain shell commands that are run every time you open a new Terminal window or tab.
- export OPENAI_API_KEY="your-api-key-here"
Alternatively, you can add this line to your ~/.zshrc to persist the key across sessions:
- echo 'export OPENAI_API_KEY="your-api-key-here"' >> ~/.zshrcÂ
- source ~/.zshrc
Configuring SGPT for Usage
Â- Default model: Choose between GPT models.
- Temperature: Control randomness in responses.
- nano ~/.config/shell_gpt/config.yaml
sgpt usage Examples: Query
 Full list of arguments
--model TEXT OpenAI model name. [default: text-davinci-003]
--max-tokens INTEGER Strict length of output (words). [default: 2048]
--shell --no-shell Get shell command as output. [default: no-shell]
--execute --no-execute Used with --shell, will execute command. [default: no-execute]
--code --no-code Provide only code as output. [default: no-code]
--spinner --no-spinner Show loading spinner during API request. [default: spinner]
--animation --no-animation Typewriter animation. [default: animation]
--help Show this message and exit.
Query Examples:
- sgpt --shell "make all files in current directory read only"
- # -> chmod 444 *
- sgpt "Explain how HTTP works."
- sgpt "Write a bash script to back up /home/user/documents to /backup."
- sgpt "Explain this Python code: def factorial(n): return 1 if n == 0 else n * factorial(n-1)"
- sgpt "Create a bash script to back up /var/log to /backup/log every night."
- sgpt "create a cron job script to run a database backup at midnight every day."
sgpt usage Examples:
Execute the shell code:Â-> chmod 444 *
-> Execute shell command? [y/N]: y
...
- sgpt --chat fp --shell "use fping to find active hosts in local network 192.168.2.0/24"
- fping -a -g 192.168.2.0/24 2>/dev/null
sgpt --chat footprint --shell "Use filetype search operator to obtain pdf files on the target website eccouncil.org and store the result in the ec-recon.txt file."curl -s "https://www.google.com/search?q=site:eccouncil.org+filetype:pdf" -A "Mozilla/5.0" | grep -oP 'https?://[^"]+\.pdf' > ec-recon.txtsgpt --chat footprint --shell "Use inurl search operator to obtail the Fortinet VPN login pages"curl -s "https://www.google.com/search?q=inurl:%22/remote/login%22+Fortinet+VPN" -A "Mozilla/5.0" | grep -oP 'https?://\S+'sgpt --chat domain --shell "Discover all the subdomains of ‘google.com’ using dig command."- sgpt --chat footprint --shell "Use Sublist3r to gather a list of subdomains of the target organization eccouncil"
- sgpt --chat fp --shell "Use theHarvester to gather hosts associated with 'microsoft.com', limiting results to 200, and leveraging 'duckduckgo' as a data source"
- baidu can be source as well
- sgpt --shell "what is my computer's dns configuration"
- nmcli dev show | grep 'IP4.DNS'
──(root㉿kali)-[~]
└─# sgpt --chat fp --shell "Use theHarvester to gather subdomains associated with 'microsoft.com', limiting results to 200, and leveraging 'duckduckgo' as a data source"
theHarvester -d microsoft.com -l 200 -b duckduckgo
[E]xecute, [D]escribe, [A]bort: E
Read proxies.yaml from /root/.theHarvester/proxies.yaml
*******************************************************************
*Â _Â Â _Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â _Â Â Â Â Â Â Â *
* | |_| |__Â Â ___Â Â /\Â /\__ _ _ ____Â Â _____Â ___| |_ ___ _ __Â *
* | __|Â _ \ / _ \Â / /_/ / _` | '__\ \ / / _ \/ __| __/ _ \ '__| *
* | |_| | | |Â __/ / __Â / (_| | |Â Â \ V /Â __/\__ \ ||Â __/ |Â Â *
*Â \__|_| |_|\___| \/ /_/ \__,_|_|Â Â \_/ \___||___/\__\___|_|Â Â *
*Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â *
* theHarvester 4.6.0Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â *
* Coded by Christian Martorella                  *
* Edge-Security Research                     *
* [email protected]Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â *
*Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â *
*******************************************************************
[*] Target: microsoft.comÂ
[*] Searching Duckduckgo.Â
[*] No IPs found.                      Â
[*] No emails found.                     Â
[*] Hosts found: 27Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
---------------------Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
2Fblogs.microsoft.com                                                Â
2Fdocs.microsoft.com                                                 Â
2Fdownload.microsoft.com                                               Â
2Fmsdn.microsoft.com                                                 Â
2Fnews.microsoft.com                                                 Â
Docs.microsoft.com                                                  Â
account.microsoft.com                                                Â
appsource.microsoft.com                                               Â
azure.microsoft.com                                                 Â
azuremarketplace.microsoft.com                                            Â
blogs.microsoft.com                                                 Â
browserdefaults.microsoft.com                                            Â
careers.microsoft.com                                                Â
choice.microsoft.com                                                 Â
copilot.microsoft.com                                                Â
developer.microsoft.com                                               Â
docs.microsoft.com                                                  Â
download.microsoft.com                                                Â
go.microsoft.com                                                   Â
learn.microsoft.com                                                 Â
msdn.microsoft.com                                                  Â
news.microsoft.com                                                  Â
privacy.microsoft.com                                                Â
schemas.microsoft.com                                                Â
support.microsoft.com                                                Â
techcommunity.microsoft.com                                             Â
visualstudio.microsoft.com Â
Usage Examples for Vulnerability Scanning
example 1: Scan for open ports
sgpt --shell "Scan 192.168.2.22 for open ports"
- nmap -p- 192.168.2.22
example 2: Scan for vulnerabilities
sgpt --shell "Scan 192.168.2.21 for vulnerabilities"
- nmap -sV --script=vuln 192.168.2.21
example 3: Use Nikto to scan for web vulnerabilities
- nikto -h 192.168.2.20
Videos
ÂReferences
- https://github.com/TheR1D/shell_gpt
No comments:
Post a Comment