Skip to content

Commit

Permalink
Updated the repository with a Security Policy, Audit, and Security Re…
Browse files Browse the repository at this point in the history
…port.

Corresponding change was made to the Software for vulnerability checking.
  • Loading branch information
wravoc committed May 12, 2023
1 parent d6ba9b6 commit b1265a7
Show file tree
Hide file tree
Showing 5 changed files with 390 additions and 3 deletions.
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ Licensees are allowed only to customize the shebang for proper execution in your
## Execution:

```sh
chmod 750 authlog-threats.py
./authlog-threats.py backup
./authlog-threats.py test
./authlog-threats.py
Expand All @@ -118,6 +117,20 @@ chmod 750 authlog-threats.py

## Installation:

Since this Software uses shell commands it is required to place it in a secure directory with permissions on the parent the Software resides in to have no permissions for `other` /all/world group to Execute and no network access.



### Software permissions:

`chmod 750 authlog-threats.py`

This ensures that for instance `wheel` can execute it but cannot write, and thus not able to shell inject.



### Crontab

```sh
# Crontab with no output, no email, running at 1AM nigthly
crontab -e
Expand All @@ -137,4 +150,14 @@ crontab -e
* **Risk** - Low
* **Impact** - Low

This script has no networking, accesses no sockets, changes nor sets permissions, only peforms one file operation per system file per mode, and does not access any system files in [full] "write" mode. It appends only to a single system file and will terminate under any error.
This script has no networking, accesses no sockets, uses only standard libraries, changes nor sets permissions, only performs one file operation per system file per mode, and does not access any system files in [full] "write" mode. It appends only to a single system file and will terminate under any error.

Although this script is using `subprocess.run(shell=True)` the only possibility of shell injection is from the paths customized by the Licensee or unauthorized access to the filesystem the script resides on in order to perform unauthorized modifications to the commands.



## Security Guidelines Included

Every Licensee is encouraged to implement the full range of guidelines in the accompanying [Security Audit]((/docs/SecurityAudit.md)) to make ensure the security of the Software and the System it runs on.

Please follow [these guidelines](/docs/SECURITY.md) should you find a vulnerability not addressed in the audit.
2 changes: 1 addition & 1 deletion authlog-threats.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
for line in authlog_content.splitlines():
logline = re.search(ip_pattern, line)
if logline is not None:
if (logline.group(0) not in threat_content) and (logline.group(0) not in whitelist_content) and (logline.group(0) != "0.0.0.0"):
if (logline.group(0) not in threat_content) and (logline.group(0) not in whitelist_content) and (logline.group(0) != "0.0.0.0"): #nosec
if test_mode:
ip_set.append(logline.group())
else:
Expand Down
189 changes: 189 additions & 0 deletions docs/BanditReport.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@

<!DOCTYPE html>
<html>
<head>

<meta charset="UTF-8">

<title>
Bandit Report
</title>

<style>

html * {
font-family: "Arial", sans-serif;
}

pre {
font-family: "Monaco", monospace;
}

.bordered-box {
border: 1px solid black;
padding-top:.5em;
padding-bottom:.5em;
padding-left:1em;
}

.metrics-box {
font-size: 1.1em;
line-height: 130%;
}

.metrics-title {
font-size: 1.5em;
font-weight: 500;
margin-bottom: .25em;
}

.issue-description {
font-size: 1.3em;
font-weight: 500;
}

.candidate-issues {
margin-left: 2em;
border-left: solid 1px; LightGray;
padding-left: 5%;
margin-top: .2em;
margin-bottom: .2em;
}

.issue-block {
border: 1px solid LightGray;
padding-left: .5em;
padding-top: .5em;
padding-bottom: .5em;
margin-bottom: .5em;
}

.issue-sev-high {
background-color: Pink;
}

.issue-sev-medium {
background-color: NavajoWhite;
}

.issue-sev-low {
background-color: LightCyan;
}

</style>
</head>

<body>

<div id="metrics">
<div class="metrics-box bordered-box">
<div class="metrics-title">
Metrics:<br>
</div>
Total lines of code: <span id="loc">202</span><br>
Total lines skipped (#nosec): <span id="nosec">0</span>
</div>
</div>




<br>
<div id="results">

<div id="issue-0">
<div class="issue-block issue-sev-low">
<b>blacklist: </b> Consider possible security implications associated with the subprocess module.<br>
<b>Test ID:</b> B404<br>
<b>Severity: </b>LOW<br>
<b>Confidence: </b>HIGH<br>
<b>CWE: </b><a href="https://cwe.mitre.org/data/definitions/78.html" target="_blank">CWE-78</a><br>
<b>File: </b><a href="authlog-threats.py" target="_blank">authlog-threats.py</a><br>
<b>Line number: </b>34<br>
<b>More info: </b><a href="https://bandit.readthedocs.io/en/1.7.5/blacklists/blacklist_imports.html#b404-import-subprocess" target="_blank">https://bandit.readthedocs.io/en/1.7.5/blacklists/blacklist_imports.html#b404-import-subprocess</a><br>

<div class="code">
<pre>
33 from datetime import datetime, date
34 import os, re, time, sys, subprocess
35
</pre>
</div>


</div>
</div>

<div id="issue-1">
<div class="issue-block issue-sev-medium">
<b>hardcoded_bind_all_interfaces: </b> Possible binding to all interfaces.<br>
<b>Test ID:</b> B104<br>
<b>Severity: </b>MEDIUM<br>
<b>Confidence: </b>MEDIUM<br>
<b>CWE: </b><a href="https://cwe.mitre.org/data/definitions/605.html" target="_blank">CWE-605</a><br>
<b>File: </b><a href="authlog-threats.py" target="_blank">authlog-threats.py</a><br>
<b>Line number: </b>195<br>
<b>More info: </b><a href="https://bandit.readthedocs.io/en/1.7.5/plugins/b104_hardcoded_bind_all_interfaces.html" target="_blank">https://bandit.readthedocs.io/en/1.7.5/plugins/b104_hardcoded_bind_all_interfaces.html</a><br>

<div class="code">
<pre>
194 if logline is not None:
195 if (logline.group(0) not in threat_content) and (logline.group(0) not in whitelist_content) and (logline.group(0) != &quot;0.0.0.0&quot;):
196 if test_mode:
</pre>
</div>


</div>
</div>

<div id="issue-2">
<div class="issue-block issue-sev-high">
<b>subprocess_popen_with_shell_equals_true: </b> subprocess call with shell=True identified, security issue.<br>
<b>Test ID:</b> B602<br>
<b>Severity: </b>HIGH<br>
<b>Confidence: </b>HIGH<br>
<b>CWE: </b><a href="https://cwe.mitre.org/data/definitions/78.html" target="_blank">CWE-78</a><br>
<b>File: </b><a href="authlog-threats.py" target="_blank">authlog-threats.py</a><br>
<b>Line number: </b>238<br>
<b>More info: </b><a href="https://bandit.readthedocs.io/en/1.7.5/plugins/b602_subprocess_popen_with_shell_equals_true.html" target="_blank">https://bandit.readthedocs.io/en/1.7.5/plugins/b602_subprocess_popen_with_shell_equals_true.html</a><br>

<div class="code">
<pre>
237 if pf_mode:
238 pf_reloaded = subprocess.run([pf_reload_rules_cmd], shell=True, timeout=1.7)
239 except subprocess.CalledProcessError as e:
</pre>
</div>


</div>
</div>

<div id="issue-3">
<div class="issue-block issue-sev-high">
<b>subprocess_popen_with_shell_equals_true: </b> subprocess call with shell=True identified, security issue.<br>
<b>Test ID:</b> B602<br>
<b>Severity: </b>HIGH<br>
<b>Confidence: </b>HIGH<br>
<b>CWE: </b><a href="https://cwe.mitre.org/data/definitions/78.html" target="_blank">CWE-78</a><br>
<b>File: </b><a href="authlog-threats.py" target="_blank">authlog-threats.py</a><br>
<b>Line number: </b>268<br>
<b>More info: </b><a href="https://bandit.readthedocs.io/en/1.7.5/plugins/b602_subprocess_popen_with_shell_equals_true.html" target="_blank">https://bandit.readthedocs.io/en/1.7.5/plugins/b602_subprocess_popen_with_shell_equals_true.html</a><br>

<div class="code">
<pre>
267 print(f&quot;\n*******************\033[38;5;75m pf reloaded \033[0;0m*********************&quot;)
268 print(f&quot;{subprocess.run([pf_stats_cmd], shell=True, timeout=1.7)}&quot;)
269 print(f&quot;*******************************************************\n&quot;)
</pre>
</div>


</div>
</div>

</div>

</body>
</html>
64 changes: 64 additions & 0 deletions docs/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Security Policy



## Report a Vulnerability

1. Open a Github Private Vulnerability Report for "Wravoc" using the "Security" Tab on the home page of the repository following [best practices](https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing/best-practices-for-writing-repository-security-advisories). Click **Report a vulnerability** to open the advisory form.
2. If you believe this vulnerability is severe or wish to send files please email [[email protected]](mailto:[email protected]) expecting a reply within 48 hours.



## How to report a vulnerability

Please include:

* Your Operating System details including:

* Who was file system owner of the Software
* What were the file system permissions on the Software
* What networking processes had access to that file
* What command was used to Execute the Software
* Where the Software was located when it was Executed

* Your Python Environment Details including:

* PDB output

* `python3 -m pdb authlog-threats.py`

* What modules were loaded at the time the Software was Executed

* ```
import sys
import pprint
# pretty print loaded modules
pprint.pprint(sys.modules)
```
* Version
* Automations
* Including automatic Python repository, pip, or relevant software updating
* Other Python scripts that had access to the Software
* What customizations you used in the Software
* Thorough details of vulnerability exploit
* What process was used to prove the exploit
* What files were touched
* Relevant shell history during the process
* Relevant sections of logs detailing this outcome
* Screenshots of all the above
* The hash and file size of the Software
## Confidentiality
Do not publically post information on how to utilize the vulnerability or details which others may find able to utilize the vulnerablity.
Loading

0 comments on commit b1265a7

Please sign in to comment.