Skip to content

Commit

Permalink
Add everything to pep8 formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
TrustedSec committed Jan 25, 2016
1 parent e2fd3e2 commit 10e43c5
Show file tree
Hide file tree
Showing 16 changed files with 488 additions and 326 deletions.
20 changes: 12 additions & 8 deletions artillery.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
# Still a work in progress.
#
#####################################################################
import time,sys,thread,os,subprocess
import time
import sys
import thread
import os
import subprocess

# check if its installed
if not os.path.isfile("/var/artillery/artillery.py"):
Expand All @@ -21,11 +25,11 @@

# create the database directories if they aren't there
if not os.path.isdir("/var/artillery/database/"):
os.makedirs("/var/artillery/database/")
os.makedirs("/var/artillery/database/")
if not os.path.isfile("/var/artillery/database/temp.database"):
filewrite = file("/var/artillery/database/temp.database", "w")
filewrite.write("")
filewrite.close()
filewrite = file("/var/artillery/database/temp.database", "w")
filewrite.write("")
filewrite.close()

# let the logfile know artillery has started successfully
write_log("[*] %s: Artillery has started successfully." % (grab_time()))
Expand All @@ -51,7 +55,7 @@
if is_posix():
time.sleep(2)
create_iptables_subset()
# start anti_dos
# start anti_dos
import src.anti_dos

# spawn honeypot
Expand All @@ -78,12 +82,12 @@
if is_config_enabled("THREAT_SERVER"):
thread.start_new_thread(threat_server, ())


# recycle IP addresses if enabled
if is_config_enabled("RECYCLE_IPS"):
thread.start_new_thread(refresh_log, ())

# pull additional source feeds from external parties other than artillery - pulls every 2 hours or ATIF threat feeds
# pull additional source feeds from external parties other than artillery
# - pulls every 2 hours or ATIF threat feeds
thread.start_new_thread(pull_source_feeds, ())

# let the program to continue to run
Expand Down
6 changes: 6 additions & 0 deletions readme/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
~~~~~~~~~~~~~~~~~~~~~~
version 1.6.1
~~~~~~~~~~~~~~~~~~~~~~

* put everything into pep8 format

~~~~~~~~~~~~~~~~~~~~~~
version 1.6
~~~~~~~~~~~~~~~~~~~~~~
Expand Down
7 changes: 4 additions & 3 deletions remove_ban.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
filewrite.close()

print "Listing all iptables looking for a match... if there is a massive amount of blocked IP's this could take a few minutes.."
proc = subprocess.Popen("iptables -L ARTILLERY -n -v --line-numbers | grep %s" % (ipaddress), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
proc = subprocess.Popen("iptables -L ARTILLERY -n -v --line-numbers | grep %s" % (
ipaddress), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

for line in proc.stdout.readlines():
line = str(line)
Expand All @@ -29,8 +30,8 @@
line = line[0]
print line
# delete it
subprocess.Popen("iptables -D ARTILLERY %s" % (line), stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)

subprocess.Popen("iptables -D ARTILLERY %s" % (line),
stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)

# if not valid then flag
else:
Expand Down
9 changes: 6 additions & 3 deletions restart_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
import signal
from src.core import *

proc = subprocess.Popen("ps -A x | grep artiller[y]", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
proc = subprocess.Popen(
"ps -A x | grep artiller[y]", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
# kill running instance of artillery
kill_artillery()

print "[*] %s: Restarting Artillery Server..." % (grab_time())
if os.path.isfile("/var/artillery/artillery.py"):
write_log("[*] %s: Restarting the Artillery Server process..." % (grab_time()))
subprocess.Popen("python /var/artillery/artillery.py &", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
write_log("[*] %s: Restarting the Artillery Server process..." %
(grab_time()))
subprocess.Popen("python /var/artillery/artillery.py &",
stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
33 changes: 22 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
# quick script for installing artillery
#
#
import subprocess,re,os,shutil
import subprocess
import re
import os
import shutil
from src.core import *
import sys

Expand All @@ -19,7 +22,8 @@
answer = "uninstall"

if not os.path.isfile("/etc/init.d/artillery"):
answer = raw_input("Do you want to install Artillery and have it automatically run when you restart [y/n]: ")
answer = raw_input(
"Do you want to install Artillery and have it automatically run when you restart [y/n]: ")

if answer.lower() in ["yes", "y"]:
if is_posix():
Expand All @@ -45,14 +49,17 @@
filewrite.write(config)
filewrite.close()
print "[*] Triggering update-rc.d on artillery to automatic start..."
subprocess.Popen("chmod +x /etc/init.d/artillery", shell=True).wait()
subprocess.Popen("update-rc.d artillery defaults", shell=True).wait()
subprocess.Popen(
"chmod +x /etc/init.d/artillery", shell=True).wait()
subprocess.Popen(
"update-rc.d artillery defaults", shell=True).wait()

# remove old method if installed previously
if os.path.isfile("/etc/init.d/rc.local"):
fileopen = file("/etc/init.d/rc.local", "r")
data = fileopen.read()
data = data.replace("sudo python /var/artillery/artillery.py &", "")
data = data.replace(
"sudo python /var/artillery/artillery.py &", "")
filewrite = file("/etc/init.d/rc.local", "w")
filewrite.write(data)
filewrite.close()
Expand All @@ -65,29 +72,33 @@
install_path = os.getcwd()
shutil.copytree(install_path, program_files + "\\Artillery\\")


if is_posix():
choice = raw_input("Do you want to keep Artillery updated? (requires internet) [y/n]: ")
choice = raw_input(
"Do you want to keep Artillery updated? (requires internet) [y/n]: ")
if choice in ["y", "yes"]:
print "[*] Checking out Artillery through github to /var/artillery"
# if old files are there
if os.path.isdir("/var/artillery/"):
shutil.rmtree('/var/artillery')
subprocess.Popen("git clone https://github.com/binarydefense/artillery /var/artillery/", shell=True).wait()
subprocess.Popen(
"git clone https://github.com/binarydefense/artillery /var/artillery/", shell=True).wait()
print "[*] Finished. If you want to update Artillery go to /var/artillery and type 'git pull'"
else:
print "[*] Copying setup files over..."
subprocess.Popen("cp -rf * /var/artillery/", shell=True).wait()

# if os is Mac Os X than create a .plist daemon - changes added by contributor - Giulio Bortot
# if os is Mac Os X than create a .plist daemon - changes added by
# contributor - Giulio Bortot
if os.path.isdir("/Library/LaunchDaemons"):
# check if file is already in place
if not os.path.isfile("/Library/LaunchDaemons/com.artillery.plist"):
print "[*] Creating com.artillery.plist in your Daemons directory"
filewrite = file("/Library/LaunchDaemons/com.artillery.plist", "w")
filewrite = file(
"/Library/LaunchDaemons/com.artillery.plist", "w")
filewrite.write('<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n<key>Disabled</key>\n<false/>\n<key>ProgramArguments</key>\n<array>\n<string>/usr/bin/python</string>\n<string>/var/artillery/artillery.py</string>\n</array>\n<key>KeepAlive</key>\n<true/>\n<key>RunAtLoad</key>\n<true/>\n<key>Label</key>\n<string>com.artillery</string>\n<key>Debug</key>\n<true/>\n</dict>\n</plist>')
print "[*] Adding right permissions"
subprocess.Popen("chown root:wheel /Library/LaunchDaemons/com.artillery.plist", shell=True).wait()
subprocess.Popen(
"chown root:wheel /Library/LaunchDaemons/com.artillery.plist", shell=True).wait()

choice = raw_input("Would you like to start Artillery now? [y/n]: ")
if choice in ["yes", "y"]:
Expand Down
3 changes: 2 additions & 1 deletion src/anti_dos.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
# basic throttle for some ports
anti_dos_ports = anti_dos_ports.split(",")
for ports in anti_dos_ports:
subprocess.Popen("iptables -A ARTILLERY -p tcp --dport %s -m limit --limit %s/minute --limit-burst %s -j ACCEPT" % (ports,anti_dos_throttle,anti_dos_burst), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).wait()
subprocess.Popen("iptables -A ARTILLERY -p tcp --dport %s -m limit --limit %s/minute --limit-burst %s -j ACCEPT" %
(ports, anti_dos_throttle, anti_dos_burst), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).wait()
7 changes: 5 additions & 2 deletions src/apache_monitor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#127.0.0.1 - - [10/Mar/2012:15:35:53 -0500] "GET /sdfsdfds.dsfds HTTP/1.1" 404 501 "-" "Mozilla/5.0 (X11; Linux i686 on x86_64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2"
# 127.0.0.1 - - [10/Mar/2012:15:35:53 -0500] "GET /sdfsdfds.dsfds
# HTTP/1.1" 404 501 "-" "Mozilla/5.0 (X11; Linux i686 on x86_64;
# rv:10.0.2) Gecko/20100101 Firefox/10.0.2"


def tail(some_file):
this_file = open(some_file)
# Go to the end of the file
this_file.seek(0,2)
this_file.seek(0, 2)

while True:
line = this_file.readline()
Expand Down
7 changes: 6 additions & 1 deletion src/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
#
# config module for configuration reading/writing/translating
#
#
# module is disabled for now as this breaks config reading

import os
Expand All @@ -13,6 +13,7 @@

from src.core import *


def get_config_path():
path = ""
# ToDo: Support for command line argument pointing to config file.
Expand All @@ -27,6 +28,7 @@ def get_config_path():
path = program_files + "\\Artillery\\config"
return path


def read_config(param):
path = get_config_path()
if is_windows():
Expand All @@ -43,6 +45,7 @@ def read_config(param):

return ""


def read_config_ini(path, param):
fileopen = file(path, "r")
for line in fileopen:
Expand All @@ -54,13 +57,15 @@ def read_config_ini(path, param):
line = line.split("=")
return line[1]


def read_config_yaml(path, param):
fileopen = open(path, "r")
configTree = yaml.safe_load(fileopen)
fileopen.close()
if (configTree):
return configTree.get(param, None)


def is_config_enabled(param):
config = read_config(param).lower()
return config in ("on", "yes", "true")
Loading

0 comments on commit 10e43c5

Please sign in to comment.