Showing posts with label Networking. Show all posts
Showing posts with label Networking. Show all posts

Mounting Samba File Sharing on Linux / Ubuntu system within single command

The command used to mount Samba file sharing is 'gio'(gnome input/output) utility.
 gio mount smb://<server_address>/<share>
Where we need to provide three things :
  • Username
  • WORKGROUP
  • Password
Example :
 $ gio mount smb://192.168.56.101/Anonymous
 Password required for share anonymous on 192.168.1.100
 User [ajay]: Anonymous
 Domain [WORKGROUP]: WORKGROUP
 Password: <-------Password_here
Automating the whole Process with a Shell script :
File : smbmount.sh
#!/bin/bash
# Mount smb file server with below credentials 
# Name : Anonymous
# WORKGROUP : WORKGROUP
# Password : Anonymous

echo -e "Anonymous\nWORKGROUP\nAnonymous" | gio mount \
smb://192.168.1.100/Anonymous >> /dev/null 2>&1

Creating an alias for smbmount.sh in .bashrc file :

Open your '.bashrc' file on any editor and at the last line add this :
 alias smbmount="~/scripts/smbmount.sh"
I put script at "~/scripts/smbmount.sh", you can change it accoring to your location. Now open a new terminal and type 'smbmount' to mount smsb share on your destro.
 $ smbmount
Cheers !!
Read more »

How to install Web for Pentester VM in Oracle Virtual Box

Web for Pentester is a pre-configured Virtual Machine ISO prepared for practicing Web Pentesting by PentesterLab. They also provide a course about Web penetration testing along with it. The course page can be found here. So its highly recommended to reviewing the course material to get a better understanding of the topic. This particular vulnerable VM focuses on web application pentesting and its fundamental elements. You can download the VM ISO from here.

Note : Some screenshots are small in sizes, so to saw them in big size please click on it.
Read more »

Curl for Web Hacking and Pentesting

In the previous post we saw the basic uses of curl. Now at this we are going to see some useful and important command as web pentesting view.

1. Get the HTTP response header

We can get header information of a website with '-I' flag
 curl -I http://www.w3.org
2. Sending GET Requests
 curl "http://www.testserver.com/example.php?name=hacke&age=30"
3. Sending POST requests 
 curl -d "name=ajay&submit=Submit" http://www.testserver.com/example.php
4. To follow a redirect location:
 curl -L http://www.testserver.com
5. Sending custom Headers : 
 curl -H "user-agent:Mozilla/5.0 (X11; Linux x86_64) " http://www.testserver.com
 curl -H "Content-Type: text/xml" http://www.testserver.com
 curl -H "Host: www.unknownsite.com" http://www.testserver.com
6. Custom User-Agent Header :

We can send custom user agent header by '-A' flag
 curl -A "Mozilla/5.0 (X11; Linux x86_64)" http://www.testserver.com
 curl -A "Mozilla/5.0 (compatible;  Windows NT 5.0)" http://www.testserver.com
7. Custom Referrer field :
 curl -e http://referersite.com http://www.testserver.com
Or we can also send custom referrer with below command
 curl -H "Referrer: http://referersite.com"  http://www.testserver.com
8. Custom Cookies : 

To send custom cookies use '-b' flag
 curl -b "name=sectree" http://www.testserver.com
To store response cookies in a file use '-c' option. We can also send cookies which is stored in a file.
 curl -b current_cookies.txt -c new_cookies.txt http://www.testserver.com
where the current_cookies.txt are being sent to the web server and new_cookies.txt are response cookies by the server which is stored and written in that file.


Read more »

How to use Curl in Linux : Curl Guide For beginners

Curl is a command line tool for getting or sending files using URL syntax. It is used to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction. We can use curl for download files from internet, sending custom HTTP ( GET and POST ) request, as FPT client, sending e-mails etc. Curl can be used in many different and interesting ways. Some of the main features of curl is :
Read more »

How to use urllib2 module in Python : A Beginners guide to urllib2 module

urllib2 is a Python module for fetching URLs. It offers a very simple interface, in the form of the urlopen function.  The urllib2 is capable of fetching URLs using a variety of different protocols and it also supports slightly complex interface for handling common situations - like basic authentication, cookies, proxies and so on. 
Read more »

Banner Grabbing with Python

In the previous post we saw the basics of banner grabbing techniques. Now we are trying to grab banners with some python scripts. In python we are going to use socket module to connect to target services. The socket module exposes the low-level C API for communicating over a network using the BSD socket interface.
Read more »

How to Map a Network Drive in Windows 7/8/10


In windows Mapping a Shared Folder or Shared Drive into a Network Drive is very easy task. When we map a Shared Folder or Shared Drives into a Network Drive, then it will show up as a new drive in the 'My Computer' or 'This PC' in windows 10. So we can easily access the shared files and documents we need, just like local hard drive. Now follow the below steps To Map a Network Drive :

Read more »

How to Share Folders/Drives and Map Network Drives in Windows 7, 8 and 10 on your Home Network

Public folder sharing in Windows based system is suitable for anyone who wish to share files with many users on their and Lan network quickly. Sharing a folder or an entire hard drive with computers, connected over Home or Lan network has a number of benifits. All the computers and devices on the network can access the shared resource.

Read more »

How to reconnect to a disconnected ssh session on Linux based SSH Server

Whenever we run a very long jobs on server over ssh, then sometimes the ssh-session will disconnected for various reasons. And when we again try connect to the server, then it will start another ssh-session. Now at that situation reconnect to a disconnected ssh session with the help of tmux utility. tmux is a terminal multiplexer, which can be used to multiplex several virtual consoles, allowing a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session. It is useful for dealing with multiple programs from a command-line interface, and for separating programs from the Unix shell that started the program. First install tmux in your system if it not installed.
 $ sudo apt-get install tmux
 So, in order to make your ssh-session capable to reconnect, first connect to your ssh-server
Read more »

How to Set up SSH keys on a Linux based Client/Server

An SSH key is an access credential in the SSH protocol. Its function is similar to that of user names and passwords, but the keys are primarily used for automated processes and for implementing single sign-on by system administrators and power users. SSH keys provide a more secure way of logging into servers with SSH than using a password alone. While a password can eventually be cracked with a brute force attack, SSH keys are nearly impossible to decipher by brute force alone. Generating a key pair provides user with two long string of characters: a public and a private key. So we can place the public key on any server, and then unlock it by connecting to it with a client that already has the private key. When the two match up, the system unlocks without the need for a password. We can increase security even more by protecting the private key with a passphrase. So lets get start.
Read more »

A Beginners Guide To SSH : How to start with SSH

The most common way of connecting to a remote Linux server is through SSH (aka Secure Shell). SSH is a secure protocol used as the primary means of connecting to Linux servers remotely. It provides a text-based interface by spawning a remote shell. After connecting, all commands you type in your local terminal are sent to the remote server and executed there. SSH uses public key cryptography for both connection and authentication. SSH is the default tool for system administrator to perform various tasks on servers remotely. In order to use SSH to access your server remotely, you will need a SSH client on your local machine. For Linux machines ssh-client is comes with built-in, and for windows machine you can use putty : https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html here.

Read more »

Setting up NAS/File Sharing Server with Samba in Ubuntu Server

This guide explains the Installation and configuration of Samba server on Ubuntu Server 16.04 (xenial). Samba is an Open-Source file sharing utility using the CIFS protocol, specifically aimed at allowing Windows and Linux servers to access the same file-systems. The normal setup is to have the data drives mounted on a Linux server and shared out using Samba and NFS. The Windows clients can then mount those drives using a Samba client and the Linux clients can mount them with NFS. Samba provides file and print services for various Microsoft Windows clients. Now we are going to install samba on newly installed minimal Ubuntu Server. and in my case I have two client operating systems:
Read more »

How to install OpenSSH Server on Ubuntu Linux 16.04

First update repository and upgrade system

    sudo apt-get update
    sudo apt-get upgrade

now install open-ssh server

    sudo apt-get install openssh-server

then check the status of ssh service by

    sudo service ssh status

Read more »

How to setup Static IP Address on Ubuntu Server 16.04 over LAN (Also works on other Linux Dist.)



Open up /etc/network/interfaces file

    sudo nano /etc/network/interfaces
 # The primary network interface  
 auto ens18  
 iface ens18 inet dhcp  
now change your primary interface 'ens18' from dhcp to static
 # The primary network interface  
 auto ens18  
 iface ens18 inet static  
Note: the primary interface ens18 will be different in your system(for example 'eth0'). Now add the following options just below the above lines
 address 192.168.0.151  
 netmask 255.255.255.0  
 network 192.168.0.0  
 broadcast 192.168.0.255  
 gateway 192.168.0.1  
 dns-nameservers 192.168.0.1  
now the configuration is look like this
 # The primary network interface  
 auto ens18  
 iface ens18 inet static  
 address 192.168.0.151  
 netmask 255.255.255.0  
 network 192.168.0.0  
 broadcast 192.168.0.255  
 gateway 192.168.0.1  
 dns-nameservers 192.168.0.1  
where the address is static ip, and at network put your router's ip address and replace '1' with '0' in in right-most place of IP address. For example 192.168.0.1 => 192.168.0.0
In broadcast put 255 at first place of your router's IP, and in gateway and dns-nameservers put your gateway (router) IP address. Now press Ctrl + O to save the file and Ctrl + X to exit. Now we need to edit the /etc/resolv.conf file.

    sudo nano /etc/resolv.conf

at this file put your gateway address in the 'nameserver' option.
 nameserver 192.168.0.1  
now save the file and restart the networking components

    sudo /etc/init.d/networking restart

Note: if by running above command the changes does not take place then just reboot the machine.

and thats it.
Read more »

Shell script to Ping your Home Lan Network

i wrote a simple shell script which ping the provided range of ip in a Lan network and shows the host is up or down.

ping.sh
 #!/bin/bash  
 # ./ping.sh <starting_address> <end_address>  
 # ./ping.sh 100 120  
 #  
 for((x=$1;x<=$2;x++))  
 do   
     ping -W1 -c1 192.168.0.$x > /dev/null  
      if [ $? -eq 0 ]  
     then  
         echo "host 192.168.0.$x : Up"  
     else  
         echo "host 192.168.0.$x : Down"  
     fi  
 done  

Now lets run it

./ping.sh 100 120




Thanks..

Read more »

Simple C Client/Server Codes For Socket Programing in Linux



Here is the codes for client/server program. And note these c sockets codes are in its simplest form without any error handling function or routine.

For TCP Sockets : 

Server.c
 #include<stdio.h>  
 #include<stdlib.h>  
 #include<string.h>  
 #include<unistd.h>  
 #include<arpa/inet.h>  
 #include<sys/types.h>  
 #include<netinet/in.h>  
 #include<sys/socket.h>  
   
 #define PORTNUM 9999  
   
 int main(int argc, char *argv[])  
 {  
     char *msg = "Hello world!\n";  
   
     struct sockaddr_in clnt; //socket info for client machine  
     struct sockaddr_in serv; //socket info for our server   
     int mysocket;  
   
     socklen_t socksize = sizeof(struct sockaddr_in);  
   
     memset(&serv, 0, sizeof(serv));  
   
     serv.sin_family = AF_INET;  
     serv.sin_addr.s_addr = htonl(INADDR_ANY);  
     serv.sin_port = htons(PORTNUM);  
       
     mysocket = socket(AF_INET, SOCK_STREAM, 0);  
   
     bind(mysocket, (struct sockaddr *)&serv, sizeof(struct sockaddr));  
     // bind serv info to mysocket   
   
     listen(mysocket, 1);  
     int consocket = accept(mysocket, (struct sockaddr *)&clnt, &socksize);  
   
     while(consocket)  
     {  
         printf("Incoming connection from %s - sending welcome\n", inet_ntoa(clnt.sin_addr));  
   
         send(consocket, msg, strlen(msg), 0);  
         close(consocket);  
         consocket = accept(mysocket, (struct sockaddr *)&clnt, &socksize);  
     }  
   
     close(mysocket);  
     return EXIT_SUCCESS;  
 }  

Client.c

 #include<stdio.h>  
 #include<stdlib.h>  
 #include<string.h>  
 #include<unistd.h>  
 #include<arpa/inet.h>  
 #include<sys/types.h>  
 #include<netinet/in.h>  
 #include<sys/socket.h>  
   
 #define MAXRECVLEN 500  
 #define PORTNUM 9999  
   
   
 int main(int aregc, char *argv[])  
 {  
     char buffer[MAXRECVLEN]; // +1 for null terminator  
     int len, mysocket;  
     struct sockaddr_in dest; // for access in sockaddr_in struct  
   
     mysocket = socket(AF_INET, SOCK_STREAM, 0);  
   
     memset(&dest, 0, sizeof(dest)); // zero the sockaddr_in struct  
   
     dest.sin_family = AF_INET;  
     dest.sin_addr.s_addr = htonl(INADDR_ANY);  
     dest.sin_port = htons(PORTNUM);  
   
     connect(mysocket, (struct sockaddr *)&dest, sizeof(struct sockaddr));  
   
     len = recv(mysocket, buffer, MAXRECVLEN - 1, 0);  
   
     buffer[len] = '\0';  
   
     printf("Received bytes : %s. \n", buffer);  
   
     close(mysocket);  
     return EXIT_SUCCESS;  
 }  

Now compile the both codes with gcc and run it. I run these programs in Ubuntu 11.10.

First compile it.

$ gcc -o server server.c  
$ gcc -o client client.c  

but remember always run server first and then client.



For UDP Sockets :

udp_server.c
 #include<stdio.h>  
 #include<stdlib.h>  
 #include<unistd.h>  
 #include<errno.h>  
 #include<string.h>  
 #include<sys/types.h>  
 #include<sys/socket.h>  
 #include<netinet/in.h>  
 #include<arpa/inet.h>  
 #include<netdb.h>  
   
 #define MYPORT 9999  
 #define MAXBUFLEN 100  
   
 int main(int argc, char *argv[])  
 {  
     struct sockaddr_in clnt;  
     struct sockaddr_in serv;  
     char BUFF[MAXBUFLEN];  
   
     int mysocket;  
     int numbytes;  
   
     memset(&serv, 0, sizeof(serv));  
   
     serv.sin_family    = AF_INET;  
     serv.sin_addr.s_addr = htonl(INADDR_ANY);  
     serv.sin_port = htons(MYPORT);  
   
     mysocket = socket(AF_INET, SOCK_DGRAM, 0);  
   
     bind(mysocket, (struct sockaddr *)&serv, sizeof(struct sockaddr));  
   
     int clnt_len = sizeof(clnt);  
   
     while(1){  
         if((numbytes = recvfrom(mysocket, BUFF, MAXBUFLEN-1, 0, (struct sockaddr *)&clnt, &clnt_len)) == -1) {  
             perror("died in recvfrom.\n");  
             exit(1);  
         }  
   
         BUFF[numbytes] = '\0';  
         printf("Recevied Packet from %s:%d\nData: %s\n\n", inet_ntoa(clnt.sin_addr), ntohs(clnt.sin_port), BUFF);  
     }  
 close(mysocket);  
 return 0;  
 }  
   

udp_client.c

 #include<stdio.h>  
 #include<stdlib.h>  
 #include<unistd.h>  
 #include<errno.h>  
 #include<string.h>  
 #include<sys/types.h>  
 #include<sys/socket.h>  
 #include<netinet/in.h>  
 #include<arpa/inet.h>  
 #include<netdb.h>  
   
 int main(int argc, char *argv[])  
 {  
     if(argc != 4){  
         printf("Usage : %s <IP> <PORT> <message>\n", argv[0]);  
         return 1;  
     }  
   
     int mysocket, PORT;  
     struct sockaddr_in dest;  
     socklen_t dest_len = sizeof(dest);  
       
     PORT = atoi(argv[2]);  
   
     memset(&dest, 0, sizeof(dest));  
   
     dest.sin_family = AF_INET;  
     dest.sin_addr.s_addr = inet_addr(argv[1]);  
     dest.sin_port = htons(PORT);  
   
     mysocket = socket(AF_INET, SOCK_DGRAM, 0);  
   
     sendto(mysocket, argv[3], strlen(argv[3]), 0, (struct sockaddr *)&dest, dest_len);  
       
     printf("Sent bytes : %s\n", argv[3]);  
     close(mysocket);  
     return 0;  
 }  
   

Compile it and run it.


So this is it. thanks for visiting. and for detailed explanations in Linux/Unix Socket Programing checkout the below given link.

Beej's Guide To Network Programing : http://beej.us/guide/bgnet/

Read more »