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


               


No comments:

Post a Comment