Welcome to bashacks’s documentation!

Bashacks is an open source (GPL) set of bash functions probably useful for programmers, security analysts and general users that need to do some low level type of operation.

In fact, there nothing really new bashacks since all functions are write using exiting software in GNU/Linux distribuitions.

But you still can have advantage in use short commands to run tasks that commomnly will require a ot of lines to be done.

Contents:

Install

In this section you can find instructions bashacks’s installation process, if you have any tips to improve, send your opinion. ;)

Requirements

  • bash >= 4
  • bc
  • binutils
  • coreutils
  • file
  • grep
  • hexdump
  • html2text
  • objdump
  • perl
  • sed
  • wget
  • zip
  • make

We consider that your system has the minimum instalation of packages, if you are using some of the below no problems.

GNU/Linux
FreeBSD (new)
OSX (new)

Download

Download the final version, download on the SourceForge. Download Bashacks

GIT

Since the end of version 1.5.0 we are working with separate branches for various activities, can have errors and problems in devel repository, but try to keep always clean master branch to your advantage.

$ git clone https://github.com/merces/bashacks.git
$ cd bashacks
# this's a optional mode, maybe there's some error in the devel branch.
$ git checkout devel

Compile

Options

all       : Just creates the file bashacks.sh
install   : Creates the file bashacks.sh, add entry in /etc/bash.bashrc and install man page
clean     : Just remove the file bashacks.sh
uninstall : remove reference the source of /etc/bash.bashrc and man page
$ make all
$ source bashacks.sh

Done that all functions can be used use bh TAB TAB and has a Sight beyond sight

Crypto

In this page, you will found information from all functions of cryptograpy on the bashacks

bh_hashcrack

This is our old function bh_unmd5 with many improvements, now can with several hashes, just update the name.

Note

Usage

bh_hascrack [hash string]

Supported hash string for decryption:

md5, sha1, sha256, sha384, sha512

#md5
$ bh_hashcrack e10adc3949ba59abbe56e057f20f883e
123456

#sha1
$ bh_hashcrack 38464bf083d958b53580c63c01e56707fd043588
rock

#sha256
$ bh_hashcrack 9ca0f72f324a7bd2c2efc64b40d1e769a473451c2b9e5dfbd54a9db53c986ba5
mamonas

#sha384
$ bh_hashcrack 504f008c8fcf8b2ed5dfcde752fc5464ab8ba064215d9c514785180d2ad7cee1ab792ad44798c
1234

#sha512
$ bh_hashcrack 5b01e57fd8ab53cc7c0d2a97585ba5a9d70f0dc966472b32736c52a4823f3fb43532dfc1e83fd2d92f1a7dbec8c401f4d7355b67accec
hack

This function has given a lot of work, many upgrades, have a good time that we have to find a good source hashed base.

bh_rot

Encrypts/Decrypts string with the Cesar Cipher using n shifts to the right.

Note

Usage

bh_rot [int] [string]

int : Aumount of jumps you want to give to the right

string : string to code or decode

$ bh_rot 3 terra
whuud
$ bh_rot 13 terra
green

bh_rotall is an implementation that accesses rot generating 1..25 results to rot.

$ bh_rotall urfn
ROT1 vsgo
ROT2 wthp
ROT3 xuiq
ROT4 yvjr
ROT5 zwks
ROT6 axlt
ROT7 bymu
ROT8 cznv
ROT9 daow
ROT10 ebpx
ROT11 fcqy
ROT12 gdrz
ROT13 hesa
ROT14 iftb
ROT15 jguc
ROT16 khvd
ROT17 liwce
ROT18 mjxf
ROT19 nkyg
ROT20 olzh
ROT21 pmai
ROT22 qnbj
ROT23 rock
ROT24 spdl
ROT25 tqem

bh_strxor

Calculates exclusive OR of each character in a string with a key.

Note

Usage

bh_strxor [key] [string]

key : int or hex

string: string to code or decode

$ bh_strxor 15 'hack'
gnld

$ bh_strxor 15 'gnld'
hack

Filesystem

This section in general has funcions for file handling.

bh_bkp

Do quick backup of file using the current system date to add the file name

Note

Usage

bh_bkp [filename]

$ bh_bkp bashacks.sh
$ ls -1
bashacks.sh
bashacks.sh.20160122

bh_findmime

Find file by mime type

Note

Usage

bh_findmime -[type] [directory]

type : -exe, -msi, -txt or -zip

directory : path

$ bh_findmime -exe ~/Downloads
/home/bashacks/Downloads//binario.exe

$ bh_findmime -txt ~/Documents
/home/bashacks/Documents//01-text.txt
/home/bashacks/Documents//ha.log

$ bh_findmime -zip ~/
/home/bashacks//crm.zip

$ bh_findmime -msi ~/
/home/bashacks//install.msi

bh_hashes

Generate md5 message digest of file or list of files.

Note

Usage

bh_hashes [filename or list of files]

problema

bh_md5rename

Generate md5 message dgest to one or more files and rename it with result.

Note

Usage

bh_md5rename [filename or list of files]

problema

bh_zipmal

Copress file in zip format with password protection. the password is virus

Note

Usage

bh_zipmal [filename]

$ bh_zipmal malware.cpl
  adding: malware.cpl (deflated 69%)
-rw-r--r-- 1 bashacks  users  30k Jan 21 23:57 malware.zip

Math

In this section, we will have many funcions of mathematics operations that help us in everyday life.

They are not complex to assemble in bash, however, nothing better than a small function to assist, nothing better that send data and get or return result, always read the code.

bh_bin2dec

This function expects a binary and return its equivalent in decimal.

Note

Usage

bh_bin2dec [binary]

binary : string in binary format.

$ bh_bin2dec 11111111
255

$ bh_bin2dec 10
2

$ bh_bin2dec 1110
14

bh_charcalc

Think of a way to make operations with ‘char’, how to sum two positions for a ‘char/string’ and return letter c or sum of the other and multiply it by 10 and returns 10 .. note:

Usage

``bh_charcalc`` [char/string] [operator] [number]

char/string   :   string or char to operation
operator :  \* + -
number :  num of operation
$ bh_charcalc A + 2
C

$ bh_charcalc A \* 255
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.......

bh_dec2bin

Opossed to bh_bin2dec this function expects a decimal for converting it into binary.

Note

Usage

bh_dec2bin [decimal]

decimal : number in decimal format.

$ bh_dec2bin 255
11111111

$ bh_dec2bin 2
10

$ bh_dec2bin 14
1110

#Example

$ for dec in {1..6};
 do
    echo "$dec = $(bh_dec2bin $dec)";
 done

1 = 1
2 = 10
3 = 11
4 = 100
5 = 101
6 = 110

bh_dec2hex

The function expects a input a decimal number it performs the conversion to hex.

Note

Usage

bh_dec2hex [decimal]

decimal: number in decimal format

$ bh_dec2hex 10
a

$ bh_dec2hex 255
ff

bh_hex2bin

Capture all submitted arguments and convert to binary

Note

Usage

bh_hex2bin [list or one hex digit]

$ bh_hex2bin abcdef 1 2 3
101010111100110111101111 1 10 11

$ bh_hex2bin 10
10000

bh_hex2dec

This’s a conversion function from hex digit to decimal digit

Note

Usage

bh_hex2dec [one or more hex digit]

$ bh_hex2dec A
10

$ bh_hex2dec FF
255

bh_hexcalc

In the same way as bh_charcalc, however, work here with hexdigit.

Note

Usage

bh_hex2cal [hex digit] [operator] [hex digit]

$ bh_hex2dec A \* 2
0xa0

$ bh_hex2bin FF + 1
0x100

bh_pow

This is a very simple operation in bash, but a little better “no bad”.

Note

Usage

bh_pow [number] [pow]

$ bh_pow 2 10
1024

$ bh_pow 9999 0
1

bh_shl

Push bits to the left by a number.

Note

Usage

bh_shl [number] [displaces] number : number to displaces displaces : left shift

$ bh_shl 2 1
4

$ bh_shl 50 2
200

bh_shr

Push bits to the rigth by a number.

Note

Usage

bh_shr [number] [displaces] number : number to displaces displaces : right shift.

$ bh_shr 4 1
4

$ bh_shr 50 2
12

bh_xor

Calculates the exclusive OR between two numbers, you can use hexdigit.

Network

bh_bin2ip

Convert a binary string into network ipaddress.

Note

Usage

bh_bin2ip binary string
$ bh_bin2ip 00001010.00001010.00000000.00000001
10.10.0.1

bh_hostcalc

Enter a network CIDR mask and know the amount of hosts

Note

Usage

bh_hostcalc [ mask cidr ]
$ bh_hostcalc 24
256

$ bh_hostcalc 25
126

bh_ip2bin

Convert network ipaddress into binary string.

Note

Usage

bh_ip2bin [ ipaddress ]
$ bh_ip2bin 192.168.0.100
11000000.10101000.00000000.01100100

bh_ip2geo

This command returnes the approximate location of informate ipaddress.

limited to 70 queries per day.

Note

Usage

bh_ip2geo [ ipaddress ]
$ bh_ip2geo 8.8.8.8
Level 3 Communications Google Mountain View US 37.386001586914 -122.08380126953 1

# last fiel represents the amount of queries
$ bh_ip2geo 107.155.91.162
Austin US 30.310600280762 -97.722702026367 2

bh_myip

This returns the external ipaddress of your network connection.

Note

Usage

bh_myip
$ bh_myip
200.251.1.1

bh_wgetr

Recursive and continue getting a partially-downloaded “if exist” file started by a previous instance of wget with randomize time.

Note

Usage

bh_wgetr [ url ]
$ bh_wgetr http://www.mentebinaria.com.br/artigos/0x1e/0x1e-maqengrevwin.html
www.mentebinaria.com.br/art 100%[==========================================>]   8.73K  --.-KB/s   in 0s
www.mentebinaria.com.br/rob 100%[==========================================>]     361  --.-KB/s   in 0s
www.mentebinaria.com.br/art 100%[==========================================>]  66.18K   132KB/s   in 0.5s
$ ls -1
www.mentebinaria.com.br
$ ls -1 www.mentebinaria.com.br/artigos/0x1e/
0x1e-maqengrevwin.html
desktop.png

bh_ipinfo

Query ipinfo.io returns reserved company network range to you, if domain not informed, your network should be considered.

Note

Usage

bh_ipinfo [ ipaddress ]
$ bh_ipinfo linuxfoundation.org
AS3701 Network for Education and Research in Oregon (NERO)
140.211.0.0/16
163.41.0.0/16
192.68.202.0/24
...

$ bh_ipinfo
ASXXXXX YOUR-ISP
255.0.0.0/8
255.200.0.0/16
255.200.200.0/24

bh_unshort

With this function you have the possibility to unshort a URL see below a example.

Note

Usage

bh_unshort [ URL string ]
$ bh_unshort http://goo.gl/l6MS
http://googleblog.blogspot.com/2009/12/making-urls-shorter-for-google-toolbar.html
$

bh_ipblacklist

Search for occurrence of the ip address in some blacklist returning [T] if positive and [F] if it is opposite..

Note

Usage

bh_ipblacklist [ ipaddress ]
$ bh_ipblacklist 77.xxx.xx.xx
== 77.xxx.xx.xx ==
[F]    TALOS
[F]    Malc0de
[F]    ZeuStracker
[F]    Projecthoneypot.org
[F]    blocklist.de
[T]    Alienvault
[F]    nothinkSSH
[F]    nothinkMalwareIRC
[F]    nothinkMalwareHTTP
[F]    SANS-TOPSOURCE

#if ipaddress is not informed will be considered the outside

$ bh_ipblacklist
== 189.x.xxx.x ==
[F]    TALOS
[F]    Malc0de
[F]    ZeuStracker
[F]    Projecthoneypot.org
[F]    blocklist.de
[F]    Alienvault
[F]    nothinkSSH
[F]    nothinkMalwareIRC
[F]    nothinkMalwareHTTP
[F]    SANS-TOPSOURCE

Programming

Session for the creation of facilitators for development in cli

bh_skel_c

Generates on the standard output C skeleton.

Note

Usage

bh_skel_c
$ bh_skel_c
#include <stdio.h>

int main(int argc, char *argv[]) {

    return 0;
}

bh_skel_python

Generates on the standard output python skeleton.

Note

Usage

bh_skel_python
$ bh_skel_python
#!/usr/bin/env python
# *-* coding: utf-8 *-*

if __name__ == '__main__':

Reversing

bh_asmgrep

With the binary attempts to find instruction asm and print 4 lines around.

Note

Usage

bh_asmgrep` [ asm instruction ] [ binary path ]
$ bh_asmgrep mov /bin/ls
....
....
....
--
409f2e:66 90                : xchg   %ax,%ax
409f30:80 7c 13 ff 2f       : cmpb   $0x2f,-0x1(%rbx,%rdx,1)
409f35:48 8d 42 ff          : lea    -0x1(%rdx),%rax
409f39:75 08                : jne    409f43 <__sprintf_chk@plt+0x7783>
409f3b:48 89 c2             : mov    %rax,%rdx
409f3e:48 39 d5             : cmp    %rdx,%rbp
409f41:75 ed                : jne    409f30 <__sprintf_chk@plt+0x7770>
409f43:48 83 c4 08          : add    $0x8,%rsp
--
.....
.....
.....

bh_asminfo

Display information of instructions asm internet is required for help us.

Note

Usage

bh_asminfo [ asm instruction ]
$ bh_asminfo mov
mov

|Code   |Mnemonic        |Description                                         |
|88 / r |MOV r/m8, r8    |Move r8 to r/m8                                     |
|89 / r |MOV r/m16, r16  |Move r16 to r/m16                                   |
|89 / r |MOV r/m32, r32  |Move r32 to r/m32                                   |
|8A / r |MOV r8, r/m8    |Move r/m8 to r8                                     |
|8B / r |MOV r16, r/m16  |Move r/m16 to r16                                   |
.......
.......
.......

bh_intel

Sets the debugger disassembly style to displays the disassembly code in Intel style.

Note

Usage

bh_intel [on | off]
$ bh_intel on
$ gdb ./input
....
(gdb) disassemble main
Dump of assembler code for function main:
0x0000000000400506 <+0>:push   rbp
0x0000000000400507 <+1>:mov    rbp,rsp:
0x000000000040050a <+4>:mov    DWORD PTR [rbp-0x4],edi
0x000000000040050d <+7>:mov    QWORD PTR [rbp-0x10],rsi
0x0000000000400511 <+11>:mov   eax,0x0
0x0000000000400516 <+16>:pop   rbp
0x0000000000400517 <+17>:ret
End of assembler dump.
(gdb)

# or off

$ bh_intel off
$ gdb ./input
(gdb) disass main
Dump of assembler code for function main:
Dump of assembler code for function main:
0x0000000000400506 <+0>:    push   %rbp
0x0000000000400507 <+1>:    mov    %rsp,%rbp
0x000000000040050a <+4>:    mov    %edi,-0x4(%rbp)
0x000000000040050d <+7>:    mov    %rsi,-0x10(%rbp)
0x0000000000400511 <+11>:   mov    $0x0,%eax
0x0000000000400516 <+16>:   pop    %rbp
0x0000000000400517 <+17>:   retq
End of assembler dump.
(gdb)

String

In this section, you are see funcions for string manipulate.

bh_asc2dec

This function performs the conversion of a char on it’s decimal equivalent.

Note

bh_asc2dec [char]

$  bh_asc2dec a
97
$ bh_asc2dec A
65

bh_asciitable

Display in the terminal ascii table, if you are a programmer knows how this’s important.

Note

bh_asciitable

$ bh_asciitable

Dec Hex    Dec Hex    Dec Hex  Dec Hex  Dec Hex  Dec Hex   Dec Hex   Dec Hex
  0 00 NUL  16 10 DLE  32 20    48 30 0  64 40 @  80 50 P   96 60 `  112 70 p
  1 01 SOH  17 11 DC1  33 21 !  49 31 1  65 41 A  81 51 Q   97 61 a  113 71 q
  2 02 STX  18 12 DC2  34 22 "  50 32 2  66 42 B  82 52 R   98 62 b  114 72 r
  3 03 ETX  19 13 DC3  35 23 #  51 33 3  67 43 C  83 53 S   99 63 c  115 73 s
  4 04 EOT  20 14 DC4  36 24 $  52 34 4  68 44 D  84 54 T  100 64 d  116 74 t
  5 05 ENQ  21 15 NAK  37 25 %  53 35 5  69 45 E  85 55 U  101 65 e  117 75 u
  6 06 ACK  22 16 SYN  38 26 &  54 36 6  70 46 F  86 56 V  102 66 f  118 76 v
  7 07 BEL  23 17 ETB  39 27 '  55 37 7  71 47 G  87 57 W  103 67 g  119 77 w
  8 08 BS   24 18 CAN  40 28 (  56 38 8  72 48 H  88 58 X  104 68 h  120 78 x
  9 09 HT   25 19 EM   41 29 )  57 39 9  73 49 I  89 59 Y  105 69 i  121 79 y
 10 0A LF   26 1A SUB  42 2A *  58 3A :  74 4A J  90 5A Z  106 6A j  122 7A z
 11 0B VT   27 1B ESC  43 2B +  59 3B ;  75 4B K  91 5B [  107 6B k  123 7B {
 12 0C FF   28 1C FS   44 2C ,  60 3C <  76 4C L  92 5C \  108 6C l  124 7C |
 13 0D CR   29 1D GS   45 2D -  61 3D =  77 4D M  93 5D ]  109 6D m  125 7D }
 14 0E SO   30 1E RS   46 2E .  62 3E >  78 4E N  94 5E ^  110 6E n  126 7E ~
 15 0F SI   31 1F US   47 2F /  63 3F ?  79 4F O  95 5F _  111 6F o  127 7F DEL

bh_dec2asc

Once having to enter a decimal returns it’s equivalent in ascii.

Note

bh_dec2asc [decimal]

decimal : dec equivalent of the ascii table to convert

$ bh_dec2asc 65
A
$ bh_dec2asc 41
)

bh_hex2str

Converts one or more bytes into a hex string to str.

Accepts as input all output formats str2hex function.

Note

bh_hex2str [hex string]

$ bh_hex2str '72 6f 63 6b'
rock
$ bh_hex2str '0x726f636b'
rock
$ bh_hex2str '0x72 0x6f 0x63 0x6b'
rock
$ bh_hex2str '{0x72, 0x6f, 0x63, 0x6b}'
rock

bh_str2hexr

Converts string in hex byte equivalent to each char (hex string). reverse mode

Note

bh_str2hexr [-x] [-0x] [-c] [-s] [string]

$ bh_str2hexr 'Fernando'
6f 64 6e 61 6e 72 65 46
$ bh_str2hexr -x 'Fernando'
\x6f\x64\x6e\x61\x6e\x72\x65\x46
$ bh_str2hexr -0x 'Fernado'
0x6f 0x64 0x6e 0x61 0x6e 0x72 0x65 0x46
$ bh_str2hexr -s 'Fernando'
0x6f646e616e726546

bh_str2hex

Converts string in hex byte equivalent to each char (hex string).

Note

bh_str2hex [-x] [-0x] [-c] [-s] [string]

$ bh_str2hex 'Fernando'
46 65 72 6e 61 6e 64 6f
$ bh_str2hex -x 'Fernando'
\x46\x65\x72\x6e\x61\x6e\x64\x6f
$ bh_str2hex -0x 'Fernado'
0x46 0x65 0x72 0x6e 0x61 0x6e 0x64 0x6f
$ bh_str2hex -s 'Fernando'
0x4665726e616e646f

bh_urldecode

Decode string with bh_urldecode from web standard to human format.

Note

bh_urldecode [encoded string]

$ bh_urldecode '%2fzzz%21%40%2e%23'
/zzz!@.#

bh_urlencode

Encoded string with bh_urlencode to web standard.

Note

bh_urlencode [string]

$ bh_urlencode '/zzz!@.#'
%2fzzz%21%40%2e%23

bh_utf8table

Show UTF8 table.

Note

bh_utf8table

$ bh_utf8table
Hex      Hex      Hex      Hex      Hex      Hex      Hex      Hex
c2 a0    c2 ac ¬  c2 b8 ¸  c3 84 Ä  c3 90 Ð  c3 9c Ü  c3 a8 è  c3 b4 ô
c2 a1 ¡  c2 ad    c2 b9 ¹  c3 85 Å  c3 91 Ñ  c3 9d Ý  c3 a9 é  c3 b5 õ
c2 a2 ¢  c2 ae ®  c2 ba º  c3 86 Æ  c3 92 Ò  c3 9e Þ  c3 aa ê  c3 b6 ö
c2 a3 £  c2 af ¯  c2 bb »  c3 87 Ç  c3 93 Ó  c3 9f ß  c3 ab ë  c3 b7 ÷
c2 a4 ¤  c2 b0 °  c2 bc ¼  c3 88 È  c3 94 Ô  c3 a0 à  c3 ac ì  c3 b8 ø
c2 a5 ¥  c2 b1 ±  c2 bd ½  c3 89 É  c3 95 Õ  c3 a1 á  c3 ad í  c3 b9 ù
c2 a6 ¦  c2 b2 ²  c2 be ¾  c3 8a Ê  c3 96 Ö  c3 a2 â  c3 ae î  c3 ba ú
c2 a7 §  c2 b3 ³  c2 bf ¿  c3 8b Ë  c3 97 ×  c3 a3 ã  c3 af ï  c3 bb û
c2 a8 ¨  c2 b4 ´  c3 80 À  c3 8c Ì  c3 98 Ø  c3 a4 ä  c3 b0 ð  c3 bc ü
c2 a9 ©  c2 b5 µ  c3 81 Á  c3 8d Í  c3 99 Ù  c3 a5 å  c3 b1 ñ  c3 bd ý
c2 aa ª  c2 b6 ¶  c3 82 Â  c3 8e Î  c3 9a Ú  c3 a6 æ  c3 b2 ò  c3 be þ
c2 ab «  c2 b7 ·  c3 83 Ã  c3 8f Ï  c3 9b Û  c3 a7 ç  c3 b3 ó  c3 bf ÿ