Skip to content

Instantly share code, notes, and snippets.

View bararchy's full-sized avatar

Bar Hofesh bararchy

View GitHub Profile
def self.rewrite_content_length(data)
new_size = data[:http_body].bytesize
if data[:http_headers].match(/Content-Length: (.*?)\r?\n/i)
data[:http_headers].gsub!(/Content-Length: (.*?)\r?\n/i, "Content-Length: #{new_size}\n")
else
data[:http_headers].strip!
data[:http_headers] << "\nContent-Length: #{new_size}\n\n"
end
data
end
@bararchy
bararchy / rproxy.rb
Last active August 29, 2015 14:20 — forked from buzztaiki/rproxy.rb
# HTTP Reverse proxy server
# Original Source: http://rubyforge.org/snippet/download.php?type=snippet&id=162
# Use case: you have several services running as different users
# for security purposes (they might even be chrooted).
# In production we use apache but for testing I prefer to use
# webrick because I find it more flexible for unit testing.
# The proxy mapping is modelled on the ProxyPass directive
# of apache. For example:
#
@bararchy
bararchy / LibInject.rb
Last active August 29, 2015 14:20
Libinjection Ruby Wrapper
module LibInject
extend FFI::Library
ffi_lib_flags :now, :global
ffi_lib 'libinjection.so'
class Sfilter < FFI::Struct
# layout :s, :pointer,
# :slen, :size_t,
# :userdata, :pointer,
# :flags, :int,
# :pos, :size_t
def self.read_for_tcp_proxy(socket)
data = socket.read_nonblock(16_384)
while socket.pending > 0
data += socket.read_nonblock(16_384)
end
data
rescue IO::WaitReadable
@bararchy
bararchy / tester.rb
Last active August 29, 2015 14:18
Testing Gsub
require 'benchmark/ips'
file = File.read("/home/unshadow/Desktop/text.txt")
data = file
Benchmark.ips do |bench|
bench.config(time: 5, warmup: 2)
bench.report("#gsub") do
unused = file.gsub(/Setting up/,'o')
file = data
@bararchy
bararchy / IRC_RCA.rb
Created December 2, 2014 14:18
Try 5
require 'securerandom'
require 'thread'
require 'prime'
require 'openssl'
require 'socket'
require 'zlib'
require 'base64'
class IRC_RSA
@bararchy
bararchy / loop.c
Created November 27, 2014 10:13
C and ruby
int authenticate(ssh_session session) {
ssh_message message;
do {
message=ssh_message_get(session);
if(!message)
break;
switch(ssh_message_type(message)){
case SSH_REQUEST_AUTH:
switch(ssh_message_subtype(message)){
case SSH_AUTH_METHOD_PASSWORD:
@bararchy
bararchy / ssh.c
Created November 25, 2014 14:07
C SSH
#include <libssh/libssh.h>
#include <libssh/server.h>
#include <libssh/callbacks.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/* some def */
int main ()
@bararchy
bararchy / Error.sh
Created November 25, 2014 10:30
sigfault
ruby sshsocket.rb
No Error: 0
No Error: 0
No Error: 0
No Error: 0
No Error: 0
should return 'SSH_OK':
sshsocket.rb:65: [BUG] Segmentation fault at 0x000000ffffffc0
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux]
@bararchy
bararchy / sshsock.rb
Last active August 29, 2015 14:10
SSHScoket v2
require 'rubygems'
require 'ffi'
module SSHSocket
extend FFI::Library
ffi_lib_flags :now, :global
ffi_lib 'libssh'
attach_function :ssh_init, [], :int
attach_function :ssh_bind_new, [], :pointer