Skip to content

Commit b55f2dd

Browse files
Arun GovindasamyArun Govindasamy
authored andcommitted
Initial commit
1 parent 4a06773 commit b55f2dd

File tree

144 files changed

+44837
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+44837
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*.ini
2+
*.pdf
3+
*.doc
4+
*.log
5+
*.csv
6+
!scanner_results.csv
7+
*.txt
8+
!requirements.txt
9+
backup
10+
data-volume
11+
*info

README.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Application Security Suite - AS{2}
2+
3+
<p align="center">
4+
<img width="1730" alt="as2-screenshot" src="https://user-images.githubusercontent.com/69586504/199255441-4aa87712-063f-4340-be76-28065f7e09d0.png">
5+
</p>
6+
7+
## About The Project
8+
9+
AS{2} aims to provide visibility, compliance, alerting and reporting capabilities. The primary focus is to integrate open-source tools used by AppSec teams in one place with better visibility.
10+
11+
AS{2} leverages Gitleaks, an open-source tool, to identify hard-coded secrets from the bitbucket server repository. It helps you track overall compliance. The integration with JIRA and Slack would be helpful for the security and engineering team to track and address the vulnerabilities.
12+
13+
## Tech stack
14+
15+
* HTML, JavaScript
16+
* Python Flask
17+
* Postgresql
18+
* Redis
19+
* Nginx
20+
21+
## Integrations
22+
23+
* Bitbucket server (on-premise)
24+
* JIRA
25+
* Slack
26+
27+
## Roadmap
28+
29+
- [x] Bitbucket server integration
30+
- [x] Hardoded-secrets integration
31+
- [ ] Analysis view
32+
- [ ] Bitbucket cloud integration
33+
- [ ] GitHub integration
34+
- [ ] SAST integration
35+
- [ ] SCA integration
36+
- [ ] DAST integration
37+
- [ ] Store passwords in the secrets manager
38+
39+
## Getting started
40+
41+
### Prerequisites
42+
43+
* Docker
44+
* Docker-compose
45+
46+
### Installation
47+
48+
1. Clone the repository
49+
50+
```sh
51+
cd /Data
52+
git clone https://github.com/govindasamyarun/testrepo
53+
```
54+
55+
2. Suppose you wish to use a different username, password, and database. Edit docker-compose.yml to update the following values. If not, skip step 2.
56+
57+
```sh
58+
pwd: /Data/application-security-suite
59+
vi docker-compose.yml
60+
```
61+
62+
```yaml
63+
as2-db-service:
64+
environment:
65+
POSTGRES_DB: <<Enter DB name>>
66+
POSTGRES_USER: <<Enter DB username>>
67+
POSTGRES_PASSWORD: <<Enter DB password>>
68+
69+
as2-app-service:
70+
environment:
71+
DB_USER: <<Enter DB username>>
72+
DB_PASSWORD: <<Enter DB password>>
73+
DB_DATABASE: <<Enter DB name>>
74+
```
75+
76+
3. Start the containers
77+
78+
```sh
79+
pwd: /Data/application-security-suite
80+
81+
docker-compose up --detach
82+
```
83+
84+
## Application setup
85+
86+
1. Access localhost on port 80
87+
88+
```sh
89+
http://127.0.0.1/
90+
```
91+
92+
2. By default, the AS{2} scan engine uses 50 threads
93+
3. It can be controlled using the config file. If you wish to use more threads to speed up the scan process then the as2-app-service docker image needs to be rebuild
94+
95+
```sh
96+
vi /Data/application-security-suite/as2-app-service/src/config.py
97+
```
98+
99+
```py
100+
class gitLeaksConfig:
101+
scanner_results_config_file_path = "/usr/src/app/reports/scanner_results.csv"
102+
thread_count = << Enter a value >>
103+
```
104+
105+
4. Navigate to settings tab
106+
5. Enter Bitbucket hostname, username and authtoken
107+
6. Make sure the authtoken does not contain any forward or backward slash
108+
7. By default, Scan all branches, Slack & JIRA notifications are set to false
109+
8. To enable Slack notifications, register an application
110+
* https://api.slack.com/apps
111+
* Set OAuth & Pernissions & Redirect URL
112+
* Install the app in the workspace
113+
* Set the scope:
114+
* channels:read
115+
* chat:write
116+
* chat:write.public
117+
* Copy the bot token
118+
9. To enable JIRA notifications, you need an EPIC ID, username and authtoken
119+
10. Scan output gets attached to the EPIC ticket
120+
11. Save the settings
121+
12. Navigate to Scan tab and initiate the scan
122+
13. The frontend makes REST API call and updates the scan status every 30 seconds once
123+
14. Once the scan is complete, you will be able to see the statistics in the home page
124+
15. The previous scan results are shown in the home page
125+
16. Use Reports tab to download the report in csv format
126+
127+
## Support
128+
129+
Use the issues tab to report any problems or issues.
130+
131+
## License
132+
133+
Distributed under the MIT License. See LICENSE for more information.
134+
135+
## Note
136+
137+
Note: I’m a self-taught programmer. The frontend code was copied from online, and I tweaked it a bit to fit into the application logic. The backend code was written entirely by myself.
138+
139+
## Contact
140+
141+
* [LinkedIn](https://www.linkedin.com/in/arungovindasamy/)
142+
* [Twitter](https://twitter.com/ArunGovindasamy)
143+
144+
## Demo
145+
146+
https://user-images.githubusercontent.com/69586504/199733400-9209cc3a-a505-4ad4-ac36-e5132dc8e82c.mp4

as2-app-service/Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM python:3.9.1
2+
3+
# Install dependencies
4+
RUN apt-get update && apt-get install -y netcat
5+
6+
# Create application user
7+
RUN useradd -ms /bin/bash as2 && \
8+
usermod -aG sudo as2
9+
10+
# Copy the source code to application home directory
11+
ADD . /usr/src/app/
12+
13+
# Limit the application user privilege
14+
RUN chown -R as2:as2 /usr/src/app && \
15+
chmod -R 764 /usr/src/app
16+
17+
# Run the container as non-root user
18+
USER as2
19+
20+
# Create empty directories
21+
RUN mkdir -p /usr/src/app/gitleaks/ && \
22+
mkdir -p /usr/src/app/downloads/
23+
24+
# Download gitleaks
25+
WORKDIR /usr/src/app/gitleaks/
26+
RUN wget https://github.com/zricethezav/gitleaks/releases/download/v8.11.2/gitleaks_8.11.2_linux_x64.tar.gz && \
27+
tar -xvzf gitleaks_8.11.2_linux_x64.tar.gz
28+
29+
# Set the working directory
30+
WORKDIR /usr/src/app/
31+
32+
# Install python dependencies
33+
RUN pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host=files.pythonhosted.org --no-cache-dir -r /usr/src/app/requirements.txt
34+
35+
# Start the application
36+
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]

as2-app-service/README.md

Whitespace-only changes.

as2-app-service/entrypoint.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
if [ "$DB_DATABASE" = "postgres" ]
4+
then
5+
echo "INFO - Waiting for PostgreSQL DB"
6+
7+
while ! nc -z $DB_HOST $DB_PORT; do
8+
sleep 0.1
9+
done
10+
11+
echo "INFO - PostgreSQL DB started"
12+
fi
13+
14+
python -u src/app.py
15+
16+
exec "$@"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"eventtime", "project", "repository", "slug", "ssh", "branch", "noOfSecrets", "StartLine", "EndLine", "StartColumn", "EndColumn", "File", "Author", "Email", "Date", "Message"

as2-app-service/requirements.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Flask
2+
waitress
3+
requests
4+
configparser
5+
schedule
6+
psycopg2
7+
Flask-SQLAlchemy
8+
Flask-Migrate
9+
redis

as2-app-service/src/app.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
from cgitb import text
2+
import os, sys, logging
3+
from flask import Flask
4+
from flask_migrate import Migrate
5+
import sqlalchemy
6+
from routes.gitLeaksRoute import gitLeaksRoute
7+
from routes.webRoute import webRoute
8+
from models.gitLeaksModel import gitLeaksDbHandler, gitLeaksSettingsTable
9+
from sqlalchemy import event, inspect
10+
from controllers.applicationSecuritySuite import as2LiteClass
11+
12+
app = Flask(__name__)
13+
14+
app.debug = False
15+
16+
# DB and Redis config
17+
app.config['SQLALCHEMY_DATABASE_URI'] = "postgresql://{}:{}@{}:{}/{}".format(os.environ['DB_USER'], os.environ['DB_PASSWORD'], os.environ['DB_HOST'], os.environ['DB_PORT'], os.environ['DB_DATABASE'])
18+
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
19+
app.config['REDIS_HOST'] = os.environ['REDIS_HOST']
20+
app.config['REDIS_PORT'] = os.environ['REDIS_PORT']
21+
22+
# Gitleaks DB handler
23+
gitLeaksDbHandler.init_app(app)
24+
migrate = Migrate(app, gitLeaksDbHandler)
25+
26+
with app.app_context():
27+
# Creates tables if not exists
28+
gitLeaksDbHandler.create_all()
29+
# Sets the cache to default during application startup process
30+
# CS - Current scan results
31+
# PS - Previous scan results
32+
as2LiteClass().write_to_cache('CS_Status', 'Not Started')
33+
as2LiteClass().write_to_cache('CS_TotalRepos', '0')
34+
as2LiteClass().write_to_cache('CS_NoOfReposScanned', '0')
35+
as2LiteClass().write_to_cache('CS_ReposNonCompliant', '0')
36+
as2LiteClass().write_to_cache('CS_NoOfSecretsFound', '0')
37+
as2LiteClass().write_to_cache('CS_PercentageCompletion', '0')
38+
as2LiteClass().write_to_cache('CS_ScanStartDate', '-')
39+
as2LiteClass().write_to_cache('CS_ScanEndDate', '-')
40+
41+
as2LiteClass().write_to_cache('PS_TotalRepos', '0')
42+
as2LiteClass().write_to_cache('PS_ReposCompliant', '0')
43+
as2LiteClass().write_to_cache('PS_ReposNonCompliant', '0')
44+
as2LiteClass().write_to_cache('PS_NoOfSecretsFound', '0')
45+
as2LiteClass().write_to_cache('PS_ScanStartDate', '-')
46+
as2LiteClass().write_to_cache('PS_ScanEndDate', '-')
47+
48+
# Sets default values to the DB during application startup
49+
if not gitLeaksDbHandler.session.query(gitLeaksSettingsTable).all():
50+
add_record = gitLeaksSettingsTable(gitleaksPath='/usr/src/app/gitleaks/gitleaks', bitbucketLimit=100, scannerScanAllBranches='false', scannerPathToDownloadRepository='/usr/src/app/downloads/', scannerResultsDirectory='/usr/src/app/', slackEnable='false', jiraEnable='false')
51+
gitLeaksDbHandler.session.add(add_record)
52+
gitLeaksDbHandler.session.commit()
53+
54+
# Routes to the html files
55+
app.register_blueprint(webRoute, url_prefix='/web')
56+
# Routes to the Gitelaks controller
57+
app.register_blueprint(gitLeaksRoute, url_prefix='/gl')
58+
59+
60+
if __name__ == "__main__":
61+
from waitress import serve
62+
serve(app, host="0.0.0.0", port=8000)

as2-app-service/src/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class gitLeaksConfig:
2+
scanner_results_config_file_path = '/usr/src/app/reports/scanner_results.csv'
3+
thread_count = 50

0 commit comments

Comments
 (0)