mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
417 lines
18 KiB
Markdown
417 lines
18 KiB
Markdown
# Kaynak kodu İncelemesi / SAST Araçları
|
||
|
||
{{#include ../../banners/hacktricks-training.md}}
|
||
|
||
## Rehber ve Araç Listeleri
|
||
|
||
- [**https://owasp.org/www-community/Source_Code_Analysis_Tools**](https://owasp.org/www-community/Source_Code_Analysis_Tools)
|
||
- [**https://github.com/analysis-tools-dev/static-analysis**](https://github.com/analysis-tools-dev/static-analysis)
|
||
|
||
## Çok Dilli Araçlar
|
||
|
||
### [Naxus - AI-Gents](https://www.naxusai.com/)
|
||
|
||
**PR'leri incelemek için ücretsiz bir paket** bulunmaktadır.
|
||
|
||
### [**Semgrep**](https://github.com/returntocorp/semgrep)
|
||
|
||
Bu bir **Açık Kaynak araçtır**.
|
||
|
||
#### Desteklenen Diller
|
||
|
||
| Kategori | Diller |
|
||
| ------------ | ----------------------------------------------------------------------------------------------------- |
|
||
| GA | C# · Go · Java · JavaScript · JSX · JSON · PHP · Python · Ruby · Scala · Terraform · TypeScript · TSX |
|
||
| Beta | Kotlin · Rust |
|
||
| Deneysel | Bash · C · C++ · Clojure · Dart · Dockerfile · Elixir · HTML · Julia · Jsonnet · Lisp · |
|
||
|
||
#### Hızlı Başlangıç
|
||
```bash
|
||
# Install https://github.com/returntocorp/semgrep#option-1-getting-started-from-the-cli
|
||
brew install semgrep
|
||
|
||
# Go to your repo code and scan
|
||
cd repo
|
||
semgrep scan --config auto
|
||
```
|
||
Ayrıca bulguları VSCode içinde almak için [**semgrep VSCode Extension**](https://marketplace.visualstudio.com/items?itemName=Semgrep.semgrep) kullanabilirsiniz.
|
||
|
||
### [**SonarQube**](https://www.sonarsource.com/products/sonarqube/downloads/)
|
||
|
||
Yüklenebilir bir **ücretsiz sürüm** bulunmaktadır.
|
||
|
||
#### Hızlı Başlangıç
|
||
```bash
|
||
# Run the paltform in docker
|
||
docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:latest
|
||
# Install cli tool
|
||
brew install sonar-scanner
|
||
|
||
# Go to localhost:9000 and login with admin:admin or admin:sonar
|
||
# Generate a local project and then a TOKEN for it
|
||
|
||
# Using the token and from the folder with the repo, scan it
|
||
cd path/to/repo
|
||
sonar-scanner \
|
||
-Dsonar.projectKey=<project-name> \
|
||
-Dsonar.sources=. \
|
||
-Dsonar.host.url=http://localhost:9000 \
|
||
-Dsonar.token=<sonar_project_token>
|
||
```
|
||
### CodeQL
|
||
|
||
Kurulabilir bir **ücretsiz sürüm** vardır, ancak lisansa göre **sadece ücretsiz codeQL sürümünü Açık Kaynak projelerinde kullanabilirsiniz**.
|
||
|
||
#### Kurulum
|
||
```bash
|
||
# Download your release from https://github.com/github/codeql-action/releases
|
||
## Example
|
||
wget https://github.com/github/codeql-action/releases/download/codeql-bundle-v2.14.3/codeql-bundle-osx64.tar.gz
|
||
|
||
# Move it to the destination folder
|
||
mkdir ~/codeql
|
||
mv codeql-bundle* ~/codeql
|
||
|
||
# Decompress it
|
||
cd ~/codeql
|
||
tar -xzvf codeql-bundle-*.tar.gz
|
||
rm codeql-bundle-*.tar.gz
|
||
|
||
# Add to path
|
||
echo 'export PATH="$PATH:/Users/username/codeql/codeql"' >> ~/.zshrc
|
||
|
||
# Check it's correctly installed
|
||
## Open a new terminal
|
||
codeql resolve qlpacks #Get paths to QL packs
|
||
```
|
||
#### Hızlı Başlangıç - Veritabanını Hazırlayın
|
||
|
||
> [!TIP]
|
||
> Yapmanız gereken ilk şey **veritabanını hazırlamak** (kod ağacını oluşturmak) ve daha sonra sorguların bunun üzerinde çalışmasını sağlamaktır.
|
||
|
||
- Codeql'in repo'nun dilini otomatik olarak tanımlamasına ve veritabanını oluşturmasına izin verebilirsiniz.
|
||
```bash
|
||
codeql database create <database> --language <language>
|
||
|
||
# Example
|
||
codeql database create /path/repo/codeql_db --source-root /path/repo
|
||
## DB will be created in /path/repo/codeql_db
|
||
```
|
||
> [!CAUTION]
|
||
> Bu **genellikle bir hata tetikler** ve birden fazla dilin belirtildiğini (veya otomatik olarak tespit edildiğini) söyler. **Bunu düzeltmek için sonraki seçenekleri kontrol edin!**
|
||
|
||
- Bunu **manuel olarak belirterek** **repo** ve **dili** yapabilirsiniz ([diller listesi](https://docs.github.com/en/code-security/codeql-cli/getting-started-with-the-codeql-cli/preparing-your-code-for-codeql-analysis#running-codeql-database-create))
|
||
```bash
|
||
codeql database create <database> --language <language> --source-root </path/to/repo>
|
||
|
||
# Example
|
||
codeql database create /path/repo/codeql_db --language javascript --source-root /path/repo
|
||
## DB will be created in /path/repo/codeql_db
|
||
```
|
||
- Eğer reposunuz **1'den fazla dil** kullanıyorsa, her dili belirterek **her dil için 1 DB** de oluşturabilirsiniz.
|
||
```bash
|
||
export GITHUB_TOKEN=ghp_32849y23hij4...
|
||
codeql database create <database> --source-root /path/to/repo --db-cluster --language "javascript,python"
|
||
|
||
# Example
|
||
export GITHUB_TOKEN=ghp_32849y23hij4...
|
||
codeql database create /path/repo/codeql_db --source-root /path/to/repo --db-cluster --language "javascript,python"
|
||
## DBs will be created in /path/repo/codeql_db/*
|
||
```
|
||
- `codeql`'in sizin için **tüm dilleri** tanımlamasına ve her dil için bir DB oluşturmasına da izin verebilirsiniz. Ona bir **GITHUB_TOKEN** vermeniz gerekiyor.
|
||
```bash
|
||
export GITHUB_TOKEN=ghp_32849y23hij4...
|
||
codeql database create <database> --db-cluster --source-root </path/to/repo>
|
||
|
||
# Example
|
||
export GITHUB_TOKEN=ghp_32849y23hij4...
|
||
codeql database create /tmp/codeql_db --db-cluster --source-root /path/repo
|
||
## DBs will be created in /path/repo/codeql_db/*
|
||
```
|
||
#### Hızlı Başlangıç - Kodu Analiz Et
|
||
|
||
> [!TIP]
|
||
> Artık kodu analiz etme zamanı geldi
|
||
|
||
Birden fazla dil kullandıysanız, **her dil için bir DB** belirtilen yolda oluşturulmuş olacaktır.
|
||
```bash
|
||
# Default analysis
|
||
codeql database analyze <database> --format=<format> --output=</out/file/path>
|
||
# Example
|
||
codeql database analyze /tmp/codeql_db/javascript --format=sarif-latest --output=/tmp/graphql_results.sarif
|
||
|
||
# Specify QL pack to use in the analysis
|
||
codeql database analyze <database> \
|
||
<qls pack> --sarif-category=<language> \
|
||
--sarif-add-baseline-file-info \ --format=<format> \
|
||
--output=/out/file/path>
|
||
# Example
|
||
codeql database analyze /tmp/codeql_db \
|
||
javascript-security-extended --sarif-category=javascript \
|
||
--sarif-add-baseline-file-info --format=sarif-latest \
|
||
--output=/tmp/sec-extended.sarif
|
||
```
|
||
#### Hızlı Başlangıç - Scriptli
|
||
```bash
|
||
export GITHUB_TOKEN=ghp_32849y23hij4...
|
||
export REPO_PATH=/path/to/repo
|
||
export OUTPUT_DIR_PATH="$REPO_PATH/codeql_results"
|
||
mkdir -p "$OUTPUT_DIR_PATH"
|
||
export FINAL_MSG="Results available in: "
|
||
|
||
echo "Creating DB"
|
||
codeql database create "$REPO_PATH/codeql_db" --db-cluster --source-root "$REPO_PATH"
|
||
for db in `ls "$REPO_PATH/codeql_db"`; do
|
||
echo "Analyzing $db"
|
||
codeql database analyze "$REPO_PATH/codeql_db/$db" --format=sarif-latest --output="${OUTPUT_DIR_PATH}/$db).sarif"
|
||
FINAL_MSG="$FINAL_MSG ${OUTPUT_DIR_PATH}/$db.sarif ,"
|
||
echo ""
|
||
done
|
||
|
||
echo $FINAL_MSG
|
||
```
|
||
Bulgu sonuçlarını [**https://microsoft.github.io/sarif-web-component/**](https://microsoft.github.io/sarif-web-component/) adresinde veya VSCode uzantısı [**SARIF viewer**](https://marketplace.visualstudio.com/items?itemName=MS-SarifVSCode.sarif-viewer) kullanarak görselleştirebilirsiniz.
|
||
|
||
Ayrıca bulguları VSCode içinde almak için [**VSCode uzantısını**](https://marketplace.visualstudio.com/items?itemName=GitHub.vscode-codeql) kullanabilirsiniz. Yine de manuel olarak bir veritabanı oluşturmanız gerekecek, ancak ardından herhangi bir dosyayı seçip `Sağ Tık` -> `CodeQL: Seçilen Dosyalarda Sorguları Çalıştır` seçeneğine tıklayabilirsiniz.
|
||
|
||
### [**Snyk**](https://snyk.io/product/snyk-code/)
|
||
|
||
**Yüklenebilir ücretsiz bir sürüm** mevcuttur.
|
||
|
||
#### Hızlı Başlangıç
|
||
```bash
|
||
# Install
|
||
sudo npm install -g snyk
|
||
|
||
# Authenticate (you can use a free account)
|
||
snyk auth
|
||
|
||
# Test for open source vulns & license issues
|
||
snyk test [--all-projects]
|
||
|
||
# Test for code vulnerabilities
|
||
## This will upload your code and you need to enable this option in: Settings > Snyk Code
|
||
snyk test code
|
||
|
||
# Test for vulns in images
|
||
snyk container test [image]
|
||
|
||
# Test for IaC vulns
|
||
snyk iac test
|
||
```
|
||
Ayrıca [**snyk VSCode Extension**](https://marketplace.visualstudio.com/items?itemName=snyk-security.snyk-vulnerability-scanner) kullanarak VSCode içinde bulgular alabilirsiniz.
|
||
|
||
### [Insider](https://github.com/insidersec/insider)
|
||
|
||
**Açık Kaynak**tır, ancak **bakım yapılmıyor** gibi görünüyor.
|
||
|
||
#### Desteklenen Diller
|
||
|
||
Java (Maven ve Android), Kotlin (Android), Swift (iOS), .NET Full Framework, C# ve Javascript (Node.js).
|
||
|
||
#### Hızlı Başlangıç
|
||
```bash
|
||
# Check the correct release for your environment
|
||
$ wget https://github.com/insidersec/insider/releases/download/2.1.0/insider_2.1.0_linux_x86_64.tar.gz
|
||
$ tar -xf insider_2.1.0_linux_x86_64.tar.gz
|
||
$ chmod +x insider
|
||
$ ./insider --tech javascript --target <projectfolder>
|
||
```
|
||
### [**DeepSource**](https://deepsource.com/pricing)
|
||
|
||
**Açık repos** için ücretsizdir.
|
||
|
||
## NodeJS
|
||
|
||
- **`yarn`**
|
||
```bash
|
||
# Install
|
||
brew install yarn
|
||
# Run
|
||
cd /path/to/repo
|
||
yarn install
|
||
yarn audit # In lower versions
|
||
yarn npm audit # In 2+ versions
|
||
|
||
npm audit
|
||
```
|
||
- **`pnpm`**
|
||
```bash
|
||
# Install
|
||
npm install -g pnpm
|
||
# Run
|
||
cd /path/to/repo
|
||
pnpm install
|
||
pnpm audit
|
||
```
|
||
- [**nodejsscan**](https://github.com/ajinabraham/nodejsscan)**:** Node.js uygulamaları için [libsast](https://github.com/ajinabraham/libsast) ve [semgrep](https://github.com/returntocorp/semgrep) tarafından desteklenen statik güvenlik kod tarayıcısı (SAST).
|
||
```bash
|
||
# Install & run
|
||
docker run -it -p 9090:9090 opensecurity/nodejsscan:latest
|
||
# Got to localhost:9090
|
||
# Upload a zip file with the code
|
||
```
|
||
- [**RetireJS**](https://github.com/RetireJS/retire.js)**:** Retire.js'in amacı, bilinen güvenlik açıklarına sahip JS-kütüphane sürümlerinin kullanımını tespit etmenize yardımcı olmaktır.
|
||
```bash
|
||
# Install
|
||
npm install -g retire
|
||
# Run
|
||
cd /path/to/repo
|
||
retire --colors
|
||
```
|
||
## Electron
|
||
|
||
- [**electronegativity**](https://github.com/doyensec/electronegativity)**:** Electron tabanlı uygulamalardaki yanlış yapılandırmaları ve güvenlik anti-paterni tanımlamak için bir araçtır.
|
||
|
||
## Python
|
||
|
||
- [**Bandit**](https://github.com/PyCQA/bandit)**:** Bandit, Python kodundaki yaygın güvenlik sorunlarını bulmak için tasarlanmış bir araçtır. Bunu yapmak için Bandit her dosyayı işler, ondan bir AST oluşturur ve AST düğümleri üzerinde uygun eklentileri çalıştırır. Bandit tüm dosyaları taradıktan sonra bir rapor oluşturur.
|
||
```bash
|
||
# Install
|
||
pip3 install bandit
|
||
|
||
# Run
|
||
bandit -r <path to folder>
|
||
```
|
||
- [**safety**](https://github.com/pyupio/safety): Safety, bilinen güvenlik açıkları için Python bağımlılıklarını kontrol eder ve tespit edilen açıklar için uygun düzeltmeleri önerir. Safety, geliştirici makinelerinde, CI/CD boru hatlarında ve üretim sistemlerinde çalıştırılabilir.
|
||
```bash
|
||
# Install
|
||
pip install safety
|
||
# Run
|
||
safety check
|
||
```
|
||
- [~~**Pyt**~~](https://github.com/python-security/pyt): Bakımı yapılmıyor.
|
||
|
||
## .NET
|
||
```bash
|
||
# dnSpy
|
||
https://github.com/0xd4d/dnSpy
|
||
|
||
# .NET compilation
|
||
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe test.cs
|
||
```
|
||
## RUST
|
||
```bash
|
||
# Install
|
||
cargo install cargo-audit
|
||
|
||
# Run
|
||
cargo audit
|
||
|
||
#Update the Advisory Database
|
||
cargo audit fetch
|
||
```
|
||
## Java
|
||
```bash
|
||
# JD-Gui
|
||
https://github.com/java-decompiler/jd-gui
|
||
|
||
# Java compilation step-by-step
|
||
javac -source 1.8 -target 1.8 test.java
|
||
mkdir META-INF
|
||
echo "Main-Class: test" > META-INF/MANIFEST.MF
|
||
jar cmvf META-INF/MANIFEST.MF test.jar test.class
|
||
```
|
||
| Görev | Komut |
|
||
| --------------- | ------------------------------------------------------- |
|
||
| Jar Çalıştır | java -jar \[jar] |
|
||
| Jar Aç | unzip -d \[output directory] \[jar] |
|
||
| Jar Oluştur | jar -cmf META-INF/MANIFEST.MF \[output jar] \* |
|
||
| Base64 SHA256 | sha256sum \[file] \| cut -d' ' -f1 \| xxd -r -p \| base64 |
|
||
| İmzayı Kaldır | rm META-INF/_.SF META-INF/_.RSA META-INF/\*.DSA |
|
||
| Jar'dan Sil | zip -d \[jar] \[file to remove] |
|
||
| Sınıfı Decompile | procyon -o . \[path to class] |
|
||
| Jar'ı Decompile | procyon -jar \[jar] -o \[output directory] |
|
||
| Sınıfı Derle | javac \[path to .java file] |
|
||
|
||
## Devam
|
||
```bash
|
||
https://github.com/securego/gosec
|
||
```
|
||
## PHP
|
||
|
||
[Psalm](https://phpmagazine.net/2018/12/find-errors-in-your-php-applications-with-psalm.html) ve [PHPStan](https://phpmagazine.net/2020/09/phpstan-pro-edition-launched.html).
|
||
|
||
### Wordpress Eklentileri
|
||
|
||
[https://www.pluginvulnerabilities.com/plugin-security-checker/](https://www.pluginvulnerabilities.com/plugin-security-checker/)
|
||
|
||
## Solidity
|
||
|
||
- [https://www.npmjs.com/package/solium](https://www.npmjs.com/package/solium)
|
||
|
||
## JavaScript
|
||
|
||
### Keşif
|
||
|
||
1. Burp:
|
||
- Spider ve içerik keşfi
|
||
- Sitemap > filtre
|
||
- Sitemap > alan adına sağ tıklayın > Etkileşim araçları > Scriptleri Bul
|
||
2. [WaybackURLs](https://github.com/tomnomnom/waybackurls):
|
||
- `waybackurls <domain> |grep -i "\.js" |sort -u`
|
||
|
||
### Statik Analiz
|
||
|
||
#### Unminimize/Beautify/Prettify
|
||
|
||
- [https://prettier.io/playground/](https://prettier.io/playground/)
|
||
- [https://beautifier.io/](https://beautifier.io/)
|
||
- Aşağıda 'Deobfuscate/Unpack' bölümünde bahsedilen bazı araçlara da bakın.
|
||
|
||
#### Deobfuscate/Unpack
|
||
|
||
**Not**: Tamamen deobfuscate etmek mümkün olmayabilir.
|
||
|
||
1. .map dosyalarını bulun ve kullanın:
|
||
- Eğer .map dosyaları açığa çıkmışsa, bunlar kolayca deobfuscate etmek için kullanılabilir.
|
||
- Genellikle, foo.js.map foo.js ile eşleşir. Manuel olarak arayın.
|
||
- [JS Miner](https://github.com/PortSwigger/js-miner) kullanarak bunları arayın.
|
||
- Aktif taramanın yapıldığından emin olun.
|
||
- '[Tips/Notes](https://github.com/minamo7sen/burp-JS-Miner/wiki#tips--notes)' bölümünü okuyun.
|
||
- Bulunduğunda, deobfuscate etmek için [Maximize](https://www.npmjs.com/package/maximize) kullanın.
|
||
2. .map dosyaları olmadan, JSnice deneyin:
|
||
- Referanslar: [http://jsnice.org/](http://jsnice.org/) & [https://www.npmjs.com/package/jsnice](https://www.npmjs.com/package/jsnice)
|
||
- İpuçları:
|
||
- jsnice.org kullanıyorsanız, "Nicify JavaScript" butonunun yanındaki seçenekler butonuna tıklayın ve "Infer types" seçeneğini kaldırarak kodu yorumlarla karıştırmamaya dikkat edin.
|
||
- Scriptin önünde boş satır bırakmadığınızdan emin olun, çünkü bu deobfuscate sürecini etkileyebilir ve yanlış sonuçlar verebilir.
|
||
3. JSNice için daha modern alternatifler arıyorsanız, aşağıdakilere göz atabilirsiniz:
|
||
|
||
- [https://github.com/pionxzh/wakaru](https://github.com/pionxzh/wakaru)
|
||
- > Javascript decompiler, unpacker ve unminify aracı Wakaru, modern frontend için Javascript decompiler'dır. Paketlenmiş ve transpile edilmiş bir kaynaktan orijinal kodu geri getirir.
|
||
- [https://github.com/j4k0xb/webcrack](https://github.com/j4k0xb/webcrack)
|
||
- > obfuscator.io'yu deobfuscate et, unminify et ve paketlenmiş javascript'i unpack et
|
||
- [https://github.com/jehna/humanify](https://github.com/jehna/humanify)
|
||
- > ChatGPT kullanarak Javascript kodunu un-minify et Bu araç, Javascript kodunu un-minify etmek için büyük dil modelleri (ChatGPT & llama2 gibi) ve diğer araçları kullanır. LLM'lerin herhangi bir yapısal değişiklik yapmadığını unutmayın - yalnızca değişkenleri ve fonksiyonları yeniden adlandırmak için ipuçları sağlar. Ağır iş, kodun 1-1 eşdeğer kalmasını sağlamak için Babel tarafından AST seviyesinde yapılır.
|
||
- [https://thejunkland.com/blog/using-llms-to-reverse-javascript-minification.html](https://thejunkland.com/blog/using-llms-to-reverse-javascript-minification.html)
|
||
- > JavaScript değişken adı minifikasyonunu tersine çevirmek için LLM'leri kullanma
|
||
|
||
3. `console.log()` kullanın;
|
||
- Sonunda dönen değeri bulun ve `console.log(<packerReturnVariable>);` olarak değiştirin, böylece deobfuscate edilmiş js çalıştırılmak yerine yazdırılır.
|
||
- Ardından, değiştirilmiş (ve hala obfuscate edilmiş) js'i [https://jsconsole.com/](https://jsconsole.com/) sayfasına yapıştırarak deobfuscate edilmiş js'in konsola yazdırıldığını görün.
|
||
- Son olarak, deobfuscate edilmiş çıktıyı [https://prettier.io/playground/](https://prettier.io/playground/) sayfasına yapıştırarak analiz için güzelleştirin.
|
||
- **Not**: Eğer hala paketlenmiş (ama farklı) js görüyorsanız, bu muhtemelen yine paketlenmiştir. Süreci tekrarlayın.
|
||
|
||
#### Referanslar
|
||
|
||
- [YouTube: DAST - Javascript Dinamik Analiz](https://www.youtube.com/watch?v=_v8r_t4v6hQ)
|
||
- [https://blog.nvisium.com/angular-for-pentesters-part-1](https://web.archive.org/web/20221226054137/https://blog.nvisium.com/angular-for-pentesters-part-1)
|
||
- [https://blog.nvisium.com/angular-for-pentesters-part-2](https://web.archive.org/web/20230204012439/https://blog.nvisium.com/angular-for-pentesters-part-2)
|
||
- [devalias](https://twitter.com/_devalias)'ın [GitHub Gists](https://gist.github.com/0xdevalias):
|
||
- [Obfuscate Edilmiş Web Uygulama Kodunu Deobfuscate Etme / Unminify Etme](https://gist.github.com/0xdevalias/d8b743efb82c0e9406fc69da0d6c6581#deobfuscating--unminifying-obfuscated-web-app-code)
|
||
- [Webpack Uygulamalarını Tersine Mühendislik](https://gist.github.com/0xdevalias/8c621c5d09d780b1d321bfdb86d67cdd#reverse-engineering-webpack-apps)
|
||
- [vs](https://gist.github.com/search?q=user:0xdevalias+javascript)
|
||
|
||
#### Araçlar
|
||
|
||
- [https://portswigger.net/burp/documentation/desktop/tools/dom-invader](https://portswigger.net/burp/documentation/desktop/tools/dom-invader)
|
||
|
||
#### Daha Az Kullanılan Referanslar
|
||
|
||
- [https://cyberchef.org/](https://cyberchef.org/)
|
||
- [https://olajs.com/javascript-prettifier](https://olajs.com/javascript-prettifier)
|
||
- [https://jshint.com/](https://jshint.com/)
|
||
- [https://github.com/jshint/jshint/](https://github.com/jshint/jshint/)
|
||
|
||
{{#include ../../banners/hacktricks-training.md}}
|