Thursday, August 10, 2017

Linux : Basic Commands

Linux

Folder Structure
  • /bin -       These are the programs that make Linux run (ie., binaries in  LInux)
  • /etc -       configuration files are stored(usually txt format )
  • /dev -      similar to Windows device drivers.
  • /var -       log files, among other files, are stored.

Note:
·         Linux is Case- Sensitive
·         Linux allows us to modify its commands by using switches
·         switches are usually letters preceded by the dash (-)
·         With most commands, you can also use either the -h switch or the --help switch after the command to obtain "help".
·         Binaries are the files that are the equivalent of executables in Windows.
·         Binaries are files that do something like echo, ls, cd, mv, etc.
·         Probably the most important variable in our environment is our PATH variable

Summary:
1.       Network : whoami, ifconfig, dig, find
2.       Editing    : touch, cat, more ,less ,Nano,grep­ ,head ,tail ,sed ,nl
3.       File and Folders    : Pwd ,cd ,ls, mkdir  ,cp ,mv(move /rename), which, whereis ,locate ,unzip, , tar xvf, chmod , nzip
4.       System   : apt-get install, gcc , ps ,PID, ./,top ,set, export, uname-a, lsmod ,modproble –v/-r/-l
5.       Misc: man, echo, PS1,clear

Commands

present working directory> pwd
move me up one level> cd ..
name of the user we're logged in> whoami
Change Directory (Cd)> cd /newfolder
Listing Command (Ls)
> ls
> ls –la
-a switch means all
-l switch, it gives us info on the security permissions, the size, etc.,
Result: drwxr—r-x ……
d- directory
read/write/execute            =owner
only read                               =group
                read/execute                       =others
Create a File (Touch)> touch newfile
Create a Directory (Mkdir) > mkdir newdirectory
Getting Help (Man) > man touch
Copying Files (Cp) > cp /etc/newfile /root
Moving Files (Mv) > mv /root/newfile /
Viewing Files (Cat, More, Less,Nano)
> cat README
> more README
> less README
> Nano README
To view beginning of the file
>head /etc/snort/snort.conf
>head -30 /etc/snort/snort.conf
To view last lines of the file>tail /etc/snort/snort.conf
Numbering Those Lines>nl snort.conf
I Grep That
Only display lines with “database” in snort.conf file
>cat /etc/snort/ snort.conf | grep database
I Sed That Works
Replace every occurrence of mysql > MySQL
>sed s/mysql/MySQL/g snort.conf > snort2.conf
If I want to only replace the third occurrence of the word mysql and save as snort2.conf
sed s/mysql/MySQL/3 snort.conf > snort2.conf
Networking (Ifconfig)>ifconfig
Changing IP Addresses>ifconfig eth0 192.168.1.115 netmask 255.255.255.0 broadcast 192.168.1.255
DNS (Domain Name Service)
Translates to the appropriate IP address.
Linux users will often refer to DNS as BIND,
>dig wonderhowto.com ns
WonderHowTo's email servers.
>dig wonderhowto.com mx
Add or remove new server in the file below:
/etc/resolv.conf
Finding Files in a Directory (Find)
> find -name aircarck-ng
> find /pentest -name aircrack-ng
PATH variable contains path to bin directory
> echo $PATH
> which ls
Finding Any File in Any Directory (Whereis)> whereis aircrack-ng
Finding Files Using the Database (Locate)>locate aircrack-ng
Unzip>unzip DVWA-1.0.8.zip -d /var/www
Command Line Package Management or Installer>apt-get install aircrack-ng
Untar>tar xvf aircrack-ng-1.2-beta1.tar
Complie>gcc aircrack-ng
Install>./aircrack-ng
Changing permissions (read ,write,edit -> owner,group,user)
                Rwx=4 2 1=7
                rwxrwxrwx =>Chmod 777 readme= Chmod owner, group, user
                rw- r- - r- - =Chmod644 = Chmod Owner read write rest is read only
Running Process
                >ps aux
                >PID 5143
                >ps –A   
top processes>top
Killing Processes
>kill 5143
>kill -9 = No prisoners
View Our Environment Variables
>set HISTSIZE=123             
>echo $HISTSIZE
Adding application to path>PATH=$PATH:/pentest/wireless/aircrack-ng
Changing Our Terminal Prompt
                >PS1= "World's Best Hacker: #"
                >export PS1
Start Apache Daemon
                Goto Applications -> Services -> HTTPD and click on apache start.
Open  browser http://localhost/
Apache's default webpage is /var/www/index.html.
                User can edit this to displayed whatever he wants
Damn Vulnerable Web Application (DVWA)
                >  nzip DVWA-1.0.8.zip -d /var/www
                > chmod 755 DVWA-1.0.8 
Checking the Kernel
>; –a
or
>cat /proc/version
To tune kernel options>less /etc/sysctl.conf
List all drivers (Add a Module ie., driver)
                > lsmod   (lsmod is old)
Or
> modprobe –l

Add a Module(driver)
                > modprobe foo
                Finding info about a module
                > modinfo -v {module-name-here}
Remove a module (Driver)> modprobe -r foo


               


Thursday, August 3, 2017

Curl : Linux , unix




Curl (https://curl.haxx.se/docs/httpscripting.html )

Note : space = %20

See the Protocol $curl --trace-ascii debugdump.txt http://www.example.com/
See the Timing     $curl --trace-ascii d.txt --trace-time http://example.com/
See the Response -o or -O.
Host        $curl --resolve www.example.org:80:127.0.0.1 http://www.example.org/
Port number
$curl http://www.example.org:1234/
$curl --proxy http://proxy.example.org:4321 http://remote.example.org/
User name and password  $curl -u user:password http://example.org/
GET         $curl https://curl.haxx.se
ONLY the headers  (--head (-I))
Save file $ curl http://www.example.com -0 example.html
Multiple URLs (get)             $curl http://url1.example.com http://url2.example.com
To send first a HEAD and then a GET:$ curl http://www.tutorialspoint.com -0 tutorialspoint.html
Redirect  $ curl www.tutorialspoint.com/unix/ --location
A GET-form uses the method GET, as specified in HTML like:
 <form method="GET" action="junk.cgi">
 <input type=text name="birthyear">
 <input type=submit name=press value="OK">
 </form>
$curl "http://www.hotmail.com/when/junk.cgi?birthyear=1905&press=OK"
POST
<form method="POST" action="junk.cgi">
 <input type=text name="birthyear">
 <input type=submit name=press value=" OK ">
 </form>
$curl --data "birthyear=1905&press=%20OK%20"  http://www.example.com/when.cgi
$curl --data-urlencode "name=I am Daniel" http://www.example.com
(replaces  space with %20)
File Upload POST
<form method="POST" enctype='multipart/form-data' action="upload.cgi">
 <input type=file name=upload>
 <input type=submit name=press value="OK">
</form>
$curl --form upload=@localfilename --form press=OK [URL]
Hidden Fields
<form method="POST" action="foobar.cgi">
 <input type=text name="birthyear">
 <input type=hidden name="person" value="daniel">
 <input type=submit name="press" value="OK">
</form>
$curl --data "birthyear=1905&press=OK&person=daniel" [URL]
send a POST and then a GET:
$curl -d score=10 http://example.com/post.cgi --next http://example.com/results.html
two POSTs $curl --data name=$curl http://url1.example.com http://url2.example.com
PUT         $curl --upload-file uploadfile http://www.example.com/receive.cgi
Basic Authentication           $curl --user name:password http://www.example.com
Other Authentication         --ntlm, --digest, --negotiate ,--anyauth
Proxy Authentication         $curl --proxy-user proxyuser:proxypassword $curl.haxx.se