Skip to content

Instantly share code, notes, and snippets.

View rms1000watt's full-sized avatar

Ryan M Smith rms1000watt

View GitHub Profile
@rms1000watt
rms1000watt / android-os-execute.java
Last active May 31, 2016 23:20
Execute OS command on Android
import android.util.Log;
import java.io.BufferedReader;
import java.io.InputStreamReader;
private void executeCommand() {
String inputLine;
String output = "";
Process process = Runtime.getRuntime().exec("cat /proc/net/xt_qtaguid/stats");
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
while ((inputLine = in.readLine()) != null) {
@rms1000watt
rms1000watt / android-service-traffic.java
Created May 31, 2016 22:53
Get network traffic information from running services on Android
import android.net.TrafficStats;
import android.app.ActivityManager;
import android.content.pm.PackageManager;
private void getServiceTraffic() {
PackageManager pm = getPackageManager();
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> runningServices = am.getRunningServices(Integer.MAX_VALUE);
for (ActivityManager.RunningServiceInfo service : runningServices) {
@rms1000watt
rms1000watt / android-http-request.java
Created May 31, 2016 23:02
Send HTTP Request on Android
import android.util.Log;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
private void sendHTTPRequest() {
@rms1000watt
rms1000watt / android-background-thread.java
Created May 31, 2016 23:18
Start background thread on Android
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.widget.TextView;
public void startWorker(View v) {
mThread.start();
}
@rms1000watt
rms1000watt / powershell-sync-http.ps1
Last active May 31, 2016 23:27
Send Synchronous HTTP Request Powershell 2
function sendHTTP
{
param( $uri, $message )
$postData = "{"
$postData += "`"message`":`""+$message+"`","
$postData += "`"name`":`"ryan`""
$postData += "}"
$request = [System.Net.WebRequest]::Create($uri)
$request.Method = "POST"
$request.Timeout = 5000
@rms1000watt
rms1000watt / bash-open-ports.sh
Created June 1, 2016 19:32
Display all open ports on a Linux machine
# http://askubuntu.com/questions/75852/how-do-i-see-which-ports-are-open
netstat -ntlp | grep LISTEN
@rms1000watt
rms1000watt / bash-remove-ssh-key.sh
Created June 1, 2016 19:37
Remove an SSH key if a key changes on a machine (like if a new VM is generated but had an old IP address).
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
# Someone could be eavesdropping on you right now (man-in-the-middle attack)!
# It is also possible that a host key has just been changed.
# The fingerprint for the RSA key sent by the remote host is
# f0:6f:50:f0:13:96:32:67:99:79:14:59:b6:32:16:16.
# Please contact your system administrator.
# Add correct host key in /Users/ryan/.ssh/known_hosts to get rid of this message.
@rms1000watt
rms1000watt / ubuntu-router-nat-dns.sh
Created June 15, 2016 20:03
Ubuntu installation as router with NAT, DNS, and isolation rules
# Ubuntu box with 2 NICs
# eth0 = WAN
# eth1 = LAN
# OR
# eth0 = larger network
# eth1 = smaller network
# Setup and install
sudo apt-get install iptables-persistent
@rms1000watt
rms1000watt / haproxy-rdp-filtering
Created June 15, 2016 20:19
HAProxy RDP Filtering
frontend rdp
mode tcp
bind 192.168.1.11:3389
tcp-request inspect-delay 2s
tcp-request content accept if RDP_COOKIE
acl userID_a19281 rdp_cookie(mstshash) -i user123
use_backend backend_a19281 if userID_a19281
acl userID_8721bc rdp_cookie(mstshash) -i user456
@rms1000watt
rms1000watt / haproxy-install.sh
Last active June 22, 2016 17:28
HAProxy 1.6 Install on Ubuntu 14.04
# Works fine on ubuntu 14.04. Gave me issues on 16.04.
sudo apt-get update -y
sudo apt-get upgrade -y
sudo add-apt-repository ppa:vbernat/haproxy-1.6
sudo apt-get dist-upgrade -y
sudo apt-get install haproxy -y
# Edit the haproxy config
sudo nano /etc/haproxy/haproxy.cfg