Friday, December 20, 2019

Web-to-Onion Proxies

There is a means allowing you to explore those hidden service residing in Tor network / Dark Web / Deep Web, and it is:

tor2web (https://www.tor2web.org/) :

Add the top level domain, ".to", at the end of the onion pseudo URL.

Tuesday, December 10, 2019

Requirement Specification of Endpoint Response Tool

1) Information Gathering
- Read Process List
- Read Details of each process
- Read "netstat -anb" information

2) Infected Endpoint Control
- Execute commands on endpoints
- Upload/Download files between endpoints and controllers
- Capture packets on endpoints

3) Security Detection Enhancement
- Built-in Malicious Code feeds that can be updated automatically
- Upload suspicious files to an on premise sandbox to analyze
- Import YARA rules
- Import Snort rules

4) Incident Response
- Block processes from sending packets
- Stop processes
- Clean / Delete infected files
- Isolate machines

5) Threat Intelligence Integration
- Asset Information Management
- Built-in Threat Intelligece feeds that can be updated automatically
- Sending alerts to SIEM through Syslog

6) Constraint
- Being able to coexist with such Antivirus as Symantec SEP

Decision Tree by Scikit-learn

#!/usr/bin/python
#Reference #1: http://benalexkeen.com/decision-tree-classifier-in-python-using-scikit-learn/
#Reference #2: https://www.datacamp.com/community/tutorials/decision-tree-classification-python
import pandas as pd

df = pd.read_csv('./alert_fast2.csv', index_col='No.')
print "Dataset Size : ", df.shape
print(df.head(10))

#We will be using Threat, Category, Proto, Src_ip, Src_port, Dst_ip, and Dst_port to predict the Result.
#Failed: Category, Src_ip, and Dst_ip are not integer values.
#df = df[['Threat', 'Category', 'Proto', 'Src_ip', 'Src_port', 'Dst_ip', 'Dst_port', 'Result']]
df = df[['Proto', 'Src_port', 'Dst_port', 'Result']]

#We need to convert those strings into integer values.
df['Result'] = df['Result'].map({'yes': 1, 'no': 0})
df['Proto'] = df['Proto'].map({'TCP': 1, 'UDP': 2, 'ICMP': 3, 'IP': 4})

#Drop any rows with missing values.
df = df.dropna()

X = df.drop('Result', axis=1)
y = df['Result']

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1)

from sklearn import tree
model = tree.DecisionTreeClassifier()

model.fit(X_train, y_train)

y_predict = model.predict(X_test)
from sklearn.metrics import accuracy_score
print "Accuracy : ", accuracy_score(y_test, y_predict)

# Making a Prediction On a New Sample
sample_one_pred = int(model.predict([[1, 1043, 80]]))
sample_two_pred = int(model.predict([[1, 1041, 80]]))
print "Sample_one_pred : ", sample_one_pred
print "Sample_two_pred : ", sample_two_pred

#Print out the tree
#from sklearn.tree.export import export_text
#from scikit.tree import export_text
#print(export_text(model))

Tuesday, December 3, 2019

Deploy SSL Offloading Reverse Proxy through Docker and NGINX

References:
1)https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
2)https://docs.nginx.com/nginx/admin-guide/security-controls/terminating-ssl-http/?_ga=2.180791975.1262112524.1575417960-988469526.1575417960


Test NGNIX docker:
#/etc/init.d/docker start
#docker pull nginx
#docker run -it nginx /bin/bash


Install essential software:
docker#apt-get update ; apt-get install net-tools vim openssl file


Generate SSL certificate and the key:
docker#openssl req -newkey rsa:2048 -nodes -keyout /etc/ssl/certs/key.pem -x509 -days 365 -out /etc/ssl/certs/certificate.pem


Modify the nginx.conf file:
docker#cd /etc/nginx
docker#cp ./nginx.conf ./nginx.conf.bak
docker#vi ./nginx.conf
Change the content of the nginx.conf to the content as follows:
---------------------------
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

stream {
    upstream stream_backend {
         server 8.8.8.8:81;
    }

    server {
        listen                443 ssl;
        proxy_pass            stream_backend;

        ssl_certificate       /etc/ssl/certs/certificate.pem;
        ssl_certificate_key   /etc/ssl/certs/key.pem;
        ssl_protocols         SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers           HIGH:!aNULL:!MD5;
        ssl_session_cache     shared:SSL:20m;
        ssl_session_timeout   4h;
        ssl_handshake_timeout 30s;
     }
}
---------------------------
:wq!
docker#/etc/init.d/nginx start


Create a new docker image:
#docker commit [CONTAINER ID] demonalex/nginx

Sunday, December 1, 2019

Quick Set up NGINX with Modsecurity through Docker

Reference: https://hub.docker.com/r/owasp/modsecurity-crs

1) Pull the docker image first:
#/etc/init.d/docker start
#docker pull owasp/modsecurity-crs

2) Suppose Apache2 is running on the TCP81 of the server, and execute the following commands:
#/etc/init.d/apache2 start

3) Run the image:
#docker run -d -p 80:80 -e PARANOIA=5 -e PROXY=1 -e PROXYLOCATION=[URL] owasp/modsecurity-crs
Example:
#docker run -d -p 80:80 -e PARANOIA=5 -e PROXY=1 -e PROXYLOCATION=http://8.8.8.8:81/ owasp/modsecurity-crs

4) Check Modsecurity's log:
#docker exec -it [CONTAINER NAME] tail -n 30 -f /var/log/modsec_audit.log
Example:
#docker exec -it sweet_swartz tail -n 30 -f /var/log/modsec_audit.log

Tuesday, November 19, 2019

Create a Docker image by modifying existing images

There are two ways to create a new Docker image, and they are shown below:
- Create images by modifying existing images
- Create images by utilizing Dockerfiles

This document is to demonstrate how to create images by modifying existing images (P.S.: The following example shows how to modify an existing image named httpd and save it as a new image named demonalex/httpd:2)
#systemctl start docker
#docker run -it httpd /bin/bash
After modifying the image, execute the following commands:
#docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
884fa8ecd4bd        httpd               "/bin/bash"         8 minutes ago       Up 8 minutes        80/tcp   hardcore_aryabhata
#docker commit 884fa8ecd4bd demonalex/httpd:2
#docker images|grep httpd
demonalex/httpd                   2                   a6a8c482adec        41 seconds ago      205MB
httpd                             latest              19459a872194        2 months ago        154MB
#docker run -it demonalex/httpd:2 /bin/bash

Sunday, November 17, 2019

Docker File Import and Export

Export Image:
#docker save [OPTIONS] IMAGE [IMAGE...]
Example:
#docker save busybox > busybox.tar


Import Image:
#docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
Example:
#docker import /path/to/exampleimage.tgz


Load Image from Files:
#docker load [OPTIONS]
Example:
#docker load < busybox.tar.gz