C2 server for the Ghostkey project.
Warning
Warning these is only a proof of concept.
The project is still in development and is not ready for real use. The project is not responsible for any damage caused by the use of this tool. Use it at your own risk.
- Set the environment variable:
SECRET_KEYas an environment variable or in your deployment environment.
$env:SECRET_KEY='test_secret_key'; go run .export SECRET_KEY=your_secret_key
go run main.go models.go routes.goyou might get these error
go run main.go models.go routes.go
2024/10/06 01:54:14 /home/anoam/github/Ghostkey_Server/main.go:27
[error] failed to initialize database, got error Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub
2024/10/06 01:54:14 Failed to connect to database: Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub
exit status 1to fix it run these sudo apt install build-essential
To register a new user, ensure you provide the SECRET_KEY along with the username and password.
curl --location 'http://localhost:5000/register_user' --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'username=new_user' --data-urlencode 'password=password123' --data-urlencode 'secret_key=your_secret_key'To log in a user:
curl --location 'http://localhost:5000/login' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=new_user' \
--data-urlencode 'password=password123' \
--cookie-jar cookies.txtTo log out the current user (requires authentication):
curl --location 'http://localhost:5000/logout' \
--cookie cookies.txtTo register a new ESP device (requires authentication):
curl --location 'http://localhost:5000/register_device' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--cookie cookies.txt \
--data-urlencode 'esp_id=esp32_1' \
--data-urlencode 'esp_secret_key=your_esp_secret_key'To send a command to an ESP device (requires authentication):
curl --location 'http://localhost:5000/command' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--cookie cookies.txt \
--data-urlencode 'esp_id=esp32_1' \
--data-urlencode 'command=your_command_here'To get a command for a specific ESP device (requires ESP authentication):
curl --location 'http://localhost:5000/get_command' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'esp_id=esp32_1' \
--data-urlencode 'esp_secret_key=your_esp_secret_key'- Make sure to replace
your_secret_keywith the actual secret key defined in your environment variables. - Replace
esp32_1andyour_esp_secret_keywith actual values relevant to your ESP devices. - All authenticated routes require a valid session cookie. The examples above use cookie-based authentication:
- First login using the
/loginendpoint which saves the session cookie tocookies.txt - Then use this cookie file with
--cookie cookies.txtfor subsequent authenticated requests
- First login using the
To register a mailer (requires authentication):
curl --location 'http://localhost:5000/register_mailer' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--cookie cookies.txt \
--data-urlencode 'esp_id=your_esp_id_here' \
--data-urlencode 'delivery_key=your_delivery_key_here' \
--data-urlencode 'encryption_password=YourEncryptionPassword'Run the server using Docker:
docker-compose up --buildThe server supports real-time synchronization between multiple instances, allowing for horizontal scaling and high availability. For details, see CLUSTER.md.
To run the server in cluster mode:
docker-compose -f docker-compose.cluster.yml up --buildIf you want to collaborate with the project or make your own version of the Ghostkey, feel free to do so. I only ask that you share with me your version of the project so I can learn from it and find ways to improve the Ghostkey.
The project is open source and is under the GPL-3.0 license, and I have no intention of changing that. Since it has the following conditions:
| Permissions | Limitations | Conditions |
|---|---|---|
| Commercial use ✔️ Modification ✔️ Distribution ✔️ Patent use ✔️ Private use ✔️ |
Liability ❌ Warranty ❌ |
License and copyright notice ℹ️ State changes ℹ️ Disclose source ℹ️ Same license ℹ️ |
