25 Methods For Pipeline Attacks
25 Methods For Pipeline Attacks
25 Methods For Pipeline Attacks
IO
RedTeamRecipe
Red Team Recipe for Fun & Profit.
Share
Follow
In this scenario, an attacker leverages the debug mode of the CI/CD pipeline to
expose environment variables containing sensitive information.
please make three real example scenario for Get credential from CI/CD Admin
Console in pipeline attacks in devsecops with tools commands and codes in one
liner command pattern stage
Retrieve AWS access and secret keys from the CI/CD admin console and pass them
as environment variables to the pipeline stage
1. Vault CLI
In this scenario, an attacker gains access to the CI/CD pipeline and modifies the
configuration of the production environment, potentially introducing security
vulnerabilities or disrupting the system.
1 import subprocess
2
3 def deploy(repo_url):
4 # Insecure configuration, command injection vulnerability
5 command = f"git clone {repo_url}"
6 subprocess.call(command, shell=True)
In this example, the deploy function is part of a deployment script. The repo_url
parameter is expected to be a valid Git repository URL. However, due to improper
input validation, an attacker can inject arbitrary commands by appending them to
the repo_url. In this case, the attacker adds a command (rm -rf /) to delete the
entire filesystem.
1 curl https://example.com/api/config
Code:
1 import os
2
3 def get_api_key():
4 # Insecure configuration, sensitive information exposure
5 return os.environ.get('API_KEY')
1 cat ~/.aws/credentials
Code:
1 import boto3
2
3 def list_buckets():
4 # Insecure configuration, sensitive information exposure
5 session = boto3.Session()
6 s3 = session.client('s3')
7 return s3.list_buckets()
In this example, the list_buckets function uses the AWS SDK to interact with
Amazon S3. The code relies on the default credential lookup behavior of the SDK,
which checks various configuration files for AWS credentials. However, the
pipeline has a security flaw where the AWS credentials are stored in an insecure
manner. An attacker can execute a command (cat ~/.aws/credentials) to retrieve
the AWS credentials and potentially gain unauthorized access to the AWS
resources.
1. Using Clair-scanner:
This command utilizes Clair-scanner, a tool that integrates with the Clair
vulnerability database, to scan a running container (<container_ip>) and generate
a report (<report_output_file>) containing the vulnerabilities found.
1. Using kube-hunter:
This command utilizes TruffleHog, a sensitive data scanner for Git repositories. It
scans the specified Git repository URL (https://example.com/git-repo.git) using
regex pattern matching and entropy analysis to identify potentially sensitive
information, such as API keys, passwords, and other secrets stored in the
repository.
1. Using circleci:
This command uses the CircleCI CLI tool to simulate the execution of a CircleCI
configuration file (config.yml) locally. It packs the configuration file using
circleci config pack, and then executes the packed configuration file using
1. Using git:
checkout {}). Finally, it performs a case-insensitive search (git grep -iE) for
This command uses Snyk, a popular security scanning tool, to test all projects and
sub-projects in the current directory. Snyk scans the codebase and its
dependencies, checking for known vulnerabilities, insecure coding practices, and
other security issues. This helps identify and address security weaknesses
introduced by insecure coding practices.
1. Using bandit:
1 bandit -r /path/to/source-code
This command utilizes Bandit, a security tool specifically designed for Python, to
perform static code analysis on the source code located at /path/to/source-code.
Bandit checks for common security issues in Python code, such as the use of
insecure cryptographic algorithms, improper handling of user input, and
potential code injection vulnerabilities. It helps identify insecure coding practices
that could lead to security vulnerabilities.
1. Using npm:
This command uses the npm audit command, which is built into the Node Package
Manager (npm), to perform a security audit of the dependencies in a Node.js
project. It checks the project’s dependencies against the National Vulnerability
Database (NVD) and provides a report highlighting any known vulnerabilities and
insecure coding practices. This helps identify and address security issues
introduced by insecurely implemented or outdated dependencies.
1. Using Retire:
1 Retire.js -c -s <path-to-project>
used libraries. The -c option shows the full file path, and the -s option suppresses
non-vulnerable lines. This helps identify and address security issues arising from
insecure or outdated third-party JavaScript dependencies.
1. Using bundle-audit:
This helps identify and address security risks arising from insecure or outdated
third-party Ruby dependencies.
Insufficient Testing
1. Using OWASP ZAP:
1 owasp-zap-cli -s -t http://example.com
This command uses OWASP ZAP (Zed Attack Proxy) Command Line Interface
(CLI) to perform automated security testing on a target website
(http://example.com). The -s option starts the scan, and the -t option specifies the
target URL. OWASP ZAP scans the target for common security vulnerabilities, such
as cross-site scripting (XSS) and SQL injection. This helps identify potential
security weaknesses resulting from insufficient testing.
1. Using goss:
This command utilizes Goss, a tool for validating system configurations and
testing infrastructure. It runs tests defined in the goss.yaml file (-f
/path/to/goss.yaml) to verify the expected state of the system. Goss validates
various aspects, including file contents, process status, and network connectivity.
This helps ensure that the system is properly configured and tested, exposing any
insufficiencies in the testing process.
1. Using junit-viewer:
This command uses JUnit-Viewer, a tool for visualizing JUnit test results. It takes
the JUnit XML test results file (--results /path/to/test-results.xml) and
generates an HTML report in the specified output directory (--output-dir
/path/to/output). This allows for easy visualization and analysis of test results,
1. Using kube-hunter:
1 kube-hunter --remote
1. Using owtf:
1 owtf -s "target_host"
This command utilizes OWTF (Open Web Application Security Project Testing
Framework), a penetration testing tool, to perform security assessments on a
target host. OWTF combines various tools and techniques to evaluate the security
of web applications and underlying systems. By targeting the host involved in the
build and deployment processes, OWTF can identify vulnerabilities and
weaknesses that might exist within the build and deployment pipeline.
Exposed Credentials
1. Using gitleaks:
1 gitleaks --repo=https://github.com/username/repo.git
This command uses Gitleaks, a tool for detecting secrets and credentials in Git
repositories, to scan a specific repository (https://github.com/username/repo.git).
Gitleaks scans the repository’s commit history and identifies any exposed
credentials, such as API keys, passwords, or sensitive information. This helps
identify potential security risks resulting from exposed credentials within the
codebase.
1. Using trufflehog:
1. Using nuclei:
1. Using auditd:
1 auditd -f -l
This command utilizes Auditd, the Linux audit framework, to view the current
audit rules and configuration. The -f option specifies that the output should be
formatted for easy readability. Auditd provides monitoring and logging
capabilities by generating logs of system events. By examining the audit rules and
configuration, one can determine if they are set up to monitor and log the
necessary security-relevant events.
1. Using splunk:
Insecure Configurations
1. Insecure Secrets Management in CI/CD Pipeline
Vulnerability Management
1. Vulnerability Scanning of Docker Images in CI/CD Pipeline
(dependency-check-report.json).
1. Here, Snyk is used to test all projects in a CI/CD pipeline for insecure libraries
or components. Insecure third-party dependencies can introduce
vulnerabilities into the pipeline. The --all-projects parameter instructs Snyk
to test all projects, and the --json flag specifies the output format as JSON.
The scan results are saved in the insecure-library-report.json file.
This command runs kube-hunter in remote mode to identify weak access controls
in a Kubernetes cluster. Weak RBAC configurations in Kubernetes can result in
unauthorized access to critical resources. The --remote flag instructs kube-hunter
to scan a remote cluster, and the --report parameter defines the file where the
findings will be saved (weak-access-controls-report.txt).
Insider Threats
1. Monitoring Code Changes for Suspicious Activity
This command lists the Git commit history for a specific author, such as “John
Doe,” within the last month. By monitoring code changes associated with
individuals who may pose an insider threat, you can identify suspicious activity
that goes beyond regular development activities. However, it’s essential to
consider privacy and legal implications when monitoring employee activities.
This Elasticsearch query retrieves logs from the last 24 hours for a specific user,
such as “John Doe.” By implementing a centralized logging system like ELK Stack
and querying relevant logs, you can search for suspicious activities or unusual
patterns that may indicate insider threats.
1 metron_monitor.sh -r insider_threat_rules.json
This command runs Apache Metron with a set of insider threat detection rules
specified in the insider_threat_rules.json file. User Behavior Analytics (UBA)
tools like Apache Metron can analyze user activities, system logs, and network
traffic to detect anomalous behavior that may indicate insider threats. The
specific rules and configurations within Metron can be tailored to your
organization’s needs.
1 md5sum your-file.zip
This command uses GnuPG (GPG) to verify the digital signature of a build (your-
build.tar.gz) by comparing it to the corresponding signature file (your-
This command inspects a Docker image (your-image:tag) and retrieves the image
digest. The image digest is a hash that uniquely identifies the image content. By
comparing the digest with the expected value, you can ensure the integrity of the
Docker image. A mismatch indicates a lack of build integrity or unauthorized
modifications.
Inadequate Testing
1. Inadequate Unit Testing in Pipeline
This command runs pytest to execute unit tests for a specific module
(your_module) in the pipeline. Inadequate unit testing can result in undetected
code vulnerabilities and weaknesses. The --cov parameter enables code coverage
analysis, providing insights into the adequacy of test coverage.
This command uses Nmap to perform a comprehensive port scan with service
version detection on a specified IP address (your-ip-address). Limited penetration
testing can miss critical vulnerabilities and weaknesses. The -p parameter
specifies the port range, -sV enables service version detection, and -sS performs a
TCP SYN scan. The -T4 parameter sets the scan speed to a moderate level.
This Elasticsearch query retrieves logs related to HTTP 500 errors in a specific
index (your-web-app-logs*) for a web application. Insufficient monitoring of web
application logs can result in missed indications of attacks or vulnerabilities. By
customizing the query, you can search for specific log events or patterns that may
indicate security issues.
This AWS CLI command queries the CloudTrail service to lookup events related to
stopping EC2 instances. Insufficient monitoring of infrastructure events can lead
to missed indicators of unauthorized access or malicious activities. By specifying
different AttributeKey and AttributeValue pairs, you can search for specific events
relevant to your infrastructure.
This command runs Bandit, a SAST tool, to scan the source code directory (your-
source-code-directory) for compliance-related issues. Lack of compliance in the
pipeline configuration can lead to security vulnerabilities. The -ll flag enables
long description output, the -f json parameter specifies the output format as
JSON, and the -o parameter defines the file where the compliance scan results will
be saved.
This AWS CLI command queries AWS Config to retrieve compliance information
for AWS EC2 instances. Insufficient governance of cloud resources can result in
non-compliant configurations and security risks. The --resource-type parameter
specifies the resource type, the --compliance-types parameter filters for non-
compliant resources, and the --output json flag formats the output as JSON. The
results are saved in the governance-report.json file.
1 GET /your-logs-index/_search?q=compliance_status:failed
Secure Configuration
https://devsecopsguides.com/docs/attacks/pipeline
https://www.cidersecurity.io/
Threat Matrix
https://github.com/rung/threat-matrix-cicd
https://speakerdeck.com/rung/cd-pipeline
Detection
https://github.com/FalconForceTeam/FalconFriday
https://cloudsecdocs.com/
OWASP
https://github.com/cider-security-research/top-10-cicd-security-risks