This file contains hidden or 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 hashlib | |
filename = '/path/to/file/file1.txt'; | |
def file_hash(filename): | |
h = hashlib.sha256() | |
with open(filename, 'rb', buffering=0) as f: | |
for b in iter(lambda : f.read(128*1024), b''): | |
h.update(b) | |
return h.hexdigest() |
This file contains hidden or 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 httplib | |
import re | |
import socket | |
import sys | |
import urllib2 | |
import ssl | |
class InvalidCertificateException(httplib.HTTPException, urllib2.URLError): | |
def __init__(self, host, cert, reason): | |
httplib.HTTPException.__init__(self) |
This file contains hidden or 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
# Create the CA Key and Certificate for signing Client Certs | |
openssl req -new -x509 -days 3650 -newkey rsa:4096 -out client.crt -keyout ca.key | |
# Create the Server Key, CSR, and Certificate | |
openssl req -new -newkey rsa:4096 -nodes -out server.csr -keyout server.key | |
# We're self signing our own server cert here. This is a no-no in production. | |
openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt | |
# Create the Client Key and CSR |
This file contains hidden or 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 socket | |
import ssl | |
def ssl_expiry_datetime(hostname): | |
ssl_date_fmt = r'%b %d %H:%M:%S %Y %Z' | |
context = ssl.create_default_context() | |
conn = context.wrap_socket( | |
socket.socket(socket.AF_INET), | |
server_hostname=hostname, |
This file contains hidden or 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
#[allow(non_snake_case)] | |
mod myMod { | |
#[allow(dead_code)] | |
pub struct Mammals<T>{ | |
pub somedata: T, | |
} | |
impl<T> Mammals<T> { | |
pub fn new(somedata: T) -> Mammals<T> { |
This file contains hidden or 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
var http = require('http'); | |
var server = undefined; | |
function HttpServer(config) { | |
this.port = config.port; | |
} | |
HttpServer.prototype.start = function (fn) { | |
server = http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'application/json'}); |
This file contains hidden or 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
var should = require('should'); | |
var request = require('request'); | |
var url = 'http://localhost:8080'; | |
var HttpServer = require('./server').HttpServer; | |
var server; | |
describe('HttpServer', function () { | |
before(function (done) { | |
server = new HttpServer({port: 8080}).start(done); |
This file contains hidden or 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
use std::io; | |
fn main() { | |
let mut user_input = String::new(); | |
io::stdin() | |
.read_line(&mut user_input) | |
.expect("failed to read from stdin"); | |
let trim_input = user_input.trim(); | |
match trim_input.parse::<u32>() { |
This file contains hidden or 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
XXE injection: | |
To use these parsers safely, you have to explicitly disable referencing of external entities in the | |
SAX parser implementation you use. | |
problem: | |
from django.http import HttpResponse | |
from lxml import etree | |
parser = etree.XMLParser(resolve_entities=True) | |
try: | |
document = etree.fromstring(content, parser) | |
except etree.XMLSyntaxError: |
This file contains hidden or 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
Excessive Logging: | |
private void logD(String message) { | |
if (BuildConfig.DEBUG) | |
Log.d(this.getLocalClassName(), message); | |
} | |
Execessive logging of sensitive security data should be avoided in prod env. |
OlderNewer