This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lambda_handler(event, context): | |
def _getParameters(paramName): | |
client = boto3.client('ssm') | |
response = client.get_parameter( | |
Name=paramName | |
) | |
return response['Parameter']['Value'] | |
inputBucketName = _getParameters('inputBucketName') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LAMBDANAME="brevity-example" | |
mkdir /home/ec2-user/environment/brevity-infra/lambdas/build/$LAMBDANAME | |
cp -r /home/ec2-user/environment/brevity-infra/lib/brevitycore /home/ec2-user/environment/brevity-infra/lambdas/build/$LAMBDANAME | |
cp /home/ec2-user/environment/brevity-infra/lambdas/lambda_function_$LAMBDANAME.py /home/ec2-user/environment/brevity-infra/lambdas/build/$LAMBDANAME/lambda_function.py | |
cd /home/ec2-user/environment/brevity-infra/lambdas/build/$LAMBDANAME | |
zip -r ../$LAMBDANAME.zip * | |
aws s3 cp /home/ec2-user/environment/brevity-infra/lambdas/build/$LAMBDANAME.zip s3://brevity-deploy/infra/ | |
aws lambda update-function-code --function-name $LAMBDANAME --s3-bucket brevity-deploy --s3-key infra/$LAMBDANAME.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NEWLAYER="brevity-example" | |
## Creating a Lambda Layer | |
## Script credits from https://towardsdatascience.com/python-packages-in-aws-lambda-made-easy-8fbc78520e30 | |
cd /home/ec2-user/environment/brevity-infra/lambdas/layers/ | |
mkdir $NEWLAYER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LAMBDANAME="brevity-example" | |
mkdir /home/ec2-user/environment/brevity-infra/lambdas/build/$LAMBDANAME | |
# Copy any custom python or dependent files to Lambda build directory | |
cp -r /home/ec2-user/environment/brevity-infra/lib/brevitycore /home/ec2-user/environment/brevity-infra/lambdas/build/$LAMBDANAME | |
# Copy the primary Lambda file to the build directory | |
cp /home/ec2-user/environment/brevity-infra/lambdas/lambda_function_$LAMBDANAME.py /home/ec2-user/environment/brevity-infra/lambdas/build/$LAMBDANAME/lambda_function.py | |
cd /home/ec2-user/environment/brevity-infra/lambdas/build/$LAMBDANAME | |
# Create the zipped Lambda package | |
zip -r ../$LAMBDANAME.zip * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def processHTTPXCrawl(programName, rawBucketPath, refinedBucketPath, inputBucketPath, presentationBucketPath): | |
filePath = refinedBucketPath + programName + '/' + programName + '-httpx-crawl.json' | |
df = pd.read_json(filePath, lines=True) | |
df['program'] = programName | |
from urllib.parse import urlparse | |
def _parseUrlRoot(urlvalue): | |
cleanurl = urlparse(urlvalue).netloc | |
return cleanurl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sonarGenerateSubdomains(programName, refinedBucketPath, ATHENA_DB, ATHENA_BUCKET, ATHENA_TABLE): | |
# Retrieve the input data to process from the list of domains | |
storePath = refinedBucketPath + programName + '/' + programName + '-domains-roots.csv' | |
dfDomainRoots = pd.read_csv(storePath) | |
# Prepare the domain roots for the query | |
dfDomainRoots['athenaquery'] = "'%." + dfDomainRoots['domain'] + "'" | |
searchDomains = dfDomainRoots['athenaquery'].tolist() | |
searchDomainString = ' OR name LIKE '.join(searchDomains) | |
# print(searchDomainString) | |
query = "SELECT * FROM %s WHERE name LIKE %s AND date = (SELECT MAX(date) from %s);" % (ATHENA_TABLE,searchDomainString,ATHENA_TABLE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generateScriptGoSpider(programName, inputBucketName): | |
fileBuffer = io.StringIO() | |
fileContents = f"""#!/bin/bash | |
# Run custom goSpider script | |
export HOME=/root | |
export PATH=/root/go/bin:$PATH | |
mkdir $HOME/security/refined/{programName} | |
mkdir $HOME/security/refined/{programName}/crawl | |
gospider -S $HOME/security/inputs/{programName}/{programName}-urls-base.csv -o $HOME/security/raw/{programName}/crawl -u web -t 1 -c 5 -d 1 --js --sitemap --robots --other-source --include-subs --include-other-source | |
cd $HOME/security/raw/{programName}/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, boto3 | |
import brevitycore | |
import digitalocean | |
def lambda_handler(event, context): | |
secretName = 'digitalocean' | |
regionName = 'us-east-1' | |
accessToken = brevitycore.get_secret(secretName,regionName) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import digitalocean | |
import json, io | |
def createDroplet(accessToken,dropletName,runOperation,programName,awsAccessKeyId,awsSecretKey): | |
def _generateUserDataScript(runOperation,programName,awsAccessKeyId,awsSecretKey): | |
import io | |
fileBuffer = io.StringIO() | |
fileContents = """#cloud-config | |
packages: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tail -f /var/log/cloud-init-output.log |