Pages

Thursday, December 28, 2023

Mastering Packet Analysis with Tcpdump - Packet Analysing.

Tcpdump is a powerful command-line packet analyzer tool used for network troubleshooting and analysis. It allows the user to intercept and display the packets transmitted or received over a network to which the computer is attached. In this guide, we'll explore how to use tcpdump for various purposes, including capturing packets, filtering traffic, and analyzing packet content.

1. Display Available Interfaces:

To see a list of available network interfaces on your system:

tcpdump -D

2. Capture Packets from a Specific Interface:

To start capturing packets from a specific interface (e.g., venet0):

tcpdump -i venet0

3. Capture Only N Number of Packets:

To limit the capture to a specific number of packets (e.g., 2 packets):

tcpdump -c 2 -i venet0

4. Print Captured Packets in ASCII:

To view the captured packets in ASCII format:

tcpdump -c 2 -A -i venet0

5. Display Captured Packets in HEX and ASCII:

To view the packet's contents in both HEX and ASCII formats:

tcpdump -c 2 -XX -i venet0

Advanced Packet Capturing

6. Capture and Save Packets in a File:

To capture packets and save them to a file for later analysis:

tcpdump -w capture.pcap -i venet0 -c 2

7. Read Captured Packets from a File:

To read packets from a previously saved file:

tcpdump -r capture.pcap

8. Capture Packets from a Specific IP Address:

To capture packets involving a particular IP address:

tcpdump -n -i venet0 -c 2 src 117.229.105.142

9. Capture Only TCP Packets:

To capture only TCP packets:

tcpdump tcp -n -i venet0 -c 2

10. Capture Packets from a Specific Port:

To capture packets from a particular port (e.g., SSH port 22):

tcpdump -i venet0 -c 2 port 22

Filtering and Analyzing Traffic

11. Capture Packets with a Readable Timestamp:

To capture packets with a more readable timestamp:

tcpdump -i venet0 -c 2 -tttt

12. Read Packets Longer than N Bytes:

To capture and read packets longer than a certain size (e.g., 10 bytes):

tcpdump -i venet0 greater 10 -c 2

13. Filter Packets – Exclude ARP and RARP:

To capture all packets other than ARP and RARP:

tcpdump -i venet0 not arp and not rarp -c 2

Conclusion

Tcpdump is an incredibly versatile tool that can be used for a wide range of network analysis tasks. By understanding how to use its various options and filters, you can diagnose network issues, monitor traffic in real-time, and perform in-depth protocol analysis. Remember, while tcpdump can capture sensitive data, it should be used responsibly and ethically. Happy analyzing!

Setting Up PostgreSQL on Your Linux System

PostgreSQL, also known as "Postgres," is a highly extensible and standards-compliant object-relational database management system (ORDBMS). It's renowned for its robustness, ACID-compliance, advanced features like multiversion concurrency control (MVCC), and a wide array of indexing methods, functions, and more. This guide will walk you through configuring your YUM repository, installing PostgreSQL, and setting up a basic database schema.

Step 1: Configure Your YUM Repository

Locate and Edit Your Distributions .repo File:

  • Fedora: Edit /etc/yum.repos.d/fedora.repo and /etc/yum.repos.d/fedora-updates.repo, specifically the [fedora] sections.
  • CentOS: Edit /etc/yum.repos.d/CentOS-Base.repo, focusing on the [base] and [updates] sections.
  • Red Hat: Edit /etc/yum/pluginconf.d/rhnplugin.conf and look for the [main] section.

Append the Exclude Line: To each of the sections identified above, append the following line to prevent the default PostgreSQL package from being installed, as it may be outdated:

exclude=postgresql*

Step 2: Download and Install the PGDG RPM File

PGDG File: PostgreSQL Global Development Group (PGDG) provides an optimized and more up-to-date version of PostgreSQL.

  1. Find the Correct RPM:

  2. Download the RPM:

    • For example, to install PostgreSQL 9.3 on CentOS 6 64-bit:
    curl -O http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm
  3. Install the RPM Distribution:

    rpm -ivh pgdg-centos93-9.3-1.noarch.rpm

Step 3: Install PostgreSQL

List Available Packages:

yum list postgres*

Install PostgreSQL Server:

  • For a basic PostgreSQL 9.3 server installation:
    yum install postgresql93-server

Step 4: Accessing PostgreSQL

Switch to the PostgreSQL User:

su - postgres

Start Using PostgreSQL:

psql

You're now in the PostgreSQL command line. Here you can manage databases, execute SQL queries, and more.

Step 5: Setting Up a Basic Database Schema

Create a Schema Called test:

CREATE SCHEMA test;

Create a Role (User) with Password:

CREATE USER xxx PASSWORD 'yyy';

Grant Privileges on New Schema to New Role:

GRANT ALL ON SCHEMA test TO xxx;

Grant Privileges on Tables in the New Schema to the New Role:

GRANT ALL ON ALL TABLES IN SCHEMA test TO xxx;

Step 6: Disconnecting

Exit psql:

\q

Conclusion

Congratulations! You've successfully set up PostgreSQL on your Linux system. You've also created your first schema and user with privileges. PostgreSQL is a powerful tool with many more capabilities and features to explore. As you become more familiar with its workings, you'll be able to leverage its full potential in managing and analyzing your data effectively. Don't forget to regularly check for updates and maintain your PostgreSQL installation to ensure security and performance.