• About

http://blog.fakrul.com

http://blog.fakrul.com

Tag Archives: BASH

Import data to Mysql

13 Tuesday Oct 2015

Posted by Fakrul Alam in Uncategorized

≈ Leave a comment

Tags

BASH, mysql

Follwoing BASH script will loop trough all the files and import them to mysql database.

#!/bin/bash

# show commands being executed, per debug
#set -x

# define database connectivity
_db="db_name"
_db_user="user_name"
_db_password="pass_word"

# define directory containing CSV files
_csv_directory="/home/fakrul/cymru_log"

# go into directory
cd $_csv_directory

# get a list of CSV files in directory
_csv_files=`ls -1 *.txt`

# loop through csv files
for _csv_file in ${_csv_files[@]}
do
echo $_csv_file

mysql -u $_db_user -p$_db_password -h localhost -D $_db --local-infile <<QUERY_INPUT
LOAD DATA local INFILE '$_csv_file'
INTO TABLE asn_data
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\n'
IGNORE 2 LINES
(report, ip, asn, time, comments, asn_name)
SET slno = NULL;

INSERT INTO file_name VALUES ('$_csv_file')
QUERY_INPUT
done

SHELL SHOCK – CVE-2014-6271

26 Friday Sep 2014

Posted by Fakrul Alam in My Work

≈ 1 Comment

Tags

BASH, SHELL SHOCK

SHELL SHOCK; A critical vulnerability has been discovered in the Bourne again shell, commonly known as bash and present in most Linux and UNIX distributions, including Mac OS X.

“GNU Bash through 4.3 processes trailing strings after function definitions in the values of environment variables, which allows remote attackers to execute arbitrary code via a crafted environment, as demonstrated by vectors involving the Force Command feature in OpenSSH sshd, the mod_cgi and mod_cgid modules in the Apache HTTP Server, scripts executed by unspecified DHCP clients, and other situations in which setting the environment occurs across a privilege boundary from Bash execution.”

To check whether your bash is vulnerable; run the following command

env x='() { :;}; echo vulnerable' bash -c "echo this is a test"

If the output is

vulnerable
this is a test

Than your system is vulnerable of the bug.

As I am using Ubuntu distro primarily; use the following command to upgrade the bash:

root@access /h/fakrul#sudo apt-get update
root@access /h/fakrul#sudo apt-get install --only-upgrade bash

It’s been very tedious to login all the server and run the command; so I use a small bash (!) command to do the same:

#!/bin/bash
servers=(
 #Put your list of servers here
    192.168.1.10
    192.168.1.100
    192.168.1.110
   )
for server in ${servers[@]}
    do
      ssh -t $server 'sudo apt-get update && sudo apt-get install --only-upgrade bash'
    done

There are few good advisory:

http://www.nzitf.org.nz/news.html

CERT Australia Publication – Bash vulnerability [PDF 665KB]

3 easy steps to create aliases file (all the users of mail server)

23 Sunday Jun 2013

Posted by Fakrul Alam in Uncategorized

≈ Leave a comment

Tags

aliases, BASH, BASH Script, postfix

Step 1: Get all the user name from /etc/passwd file

root@access /h/fakrul# awk -F’:’ ‘{ print $1 }’ /etc/passwd > userlist.txt

Step 2: Add , at end of each line

root@access /h/fakrul# sed -e ‘s/$/,/’ userlist > userlist2.txt

Step 3: Remove all the line break and replace them with space

root@access /h/fakrul# sed ‘:a;N;$!ba;s/n/ /g’ userlist2.txt > userlist3.txt

Now create the desire aliases file from this txt file.

Empty Mail Trash Folder

23 Monday Feb 2009

Posted by Fakrul Alam in Uncategorized

≈ Leave a comment

Tags

BASH, linux, Mail Server, My Work, Shell Script, Trash Folder

User always forget to empty there trash folder. User delete mail from there inbox; but don’t delete those mail from Trash folder. At the end, it eats up a lot of your server disk space. Empty this Trash folder is big headache for the administrator. Shell script can easily rescue the administrator. First create a list for you user. You can create it easily from awk commad. Save it in a file named user. Now create a new bassh file named trash_empty.sh and chown it to 755. Add the following syntex to the trash_empty.sh file

#!/bin/sh
for i in `more user`
do
echo $i
cat /dev/null > $i/mail/Trash
done

[user Trash folder in /home/username/mail/Trash. It may varies depending on your mail server configuration. ]

Now run the file trash_empty.sh WOW all your users Trash folder will be empty 🙂

Please take your own responsibility to empty users trash folder 🙂

Create user & Change password by BASH Script

09 Monday Oct 2006

Posted by Fakrul Alam in Uncategorized

≈ Leave a comment

Tags

BASH, BASH Script, Change Password, Shell Script, Tutorial

This two scripts are very important for the system admin who regularly works with mail server and some how forget to backup their system username and password!!!. Let’s say some how we lost the server username and password of the mail server. In this case the admin has to manually create all the users and than change the password for all the user. Tedious job :-). Let’s make our life easier.

First create a file which contains all the user name. Something like this:



nurealam
nayeem
mrahman
farid
rubi
sankar




Save the file as userlist.txt

Now create the following bash file:



#!/bin/sh
for i in `more userlist.txt `
do
echo $i
adduser $i
done

Save the file and exit. chmod 755 userlist.txt. Now run the file by ./userlist.txt. This will add all the user to the system.

Now we have to change the password. Lets say we want username123 as password. So for user nayeem the password will be nayeem123, rubi123 for user rubi and so on.


Create another bash file as following:



#!/bin/sh
for i in `more userlist.txt `
do
echo $i
echo $i”123” | passwd —stdin “$i”
echo; echo “User $username’s password changed!”
done

Run the file. All the password are changed 🙂

Social

  • View rapappu’s profile on Twitter
  • View fakrulalam’s profile on LinkedIn
  • View fakrul’s profile on GitHub
  • View FakrulAlamPappu’s profile on Google+
  • View fakrulalam’s profile on Flickr

Twitter Updates

  • krebsonsecurity.com/2021/03/whistl… 1 week ago
  • very production vs code extension marketplace.visualstudio.com/items?itemName… 1 week ago
  • afr.com/companies/tour… 1 week ago
  • RT @Tyriar: We're looking at finally adding terminal tabs to @code soon. This month we explored what the UX should look like and have some… 2 weeks ago
  • RT @teamcymru: April 7 at 10AM GMT +3 We're hosting a webinar on our FREE community services! Live DEMO of Nimbus and learn about • DDoS mi… 2 weeks ago
  • Interesting! Looks like #cloudflare is not just a CDN only. cloudflare.com/en-au/magic-wan 2 weeks ago
  • still beta but good to see #meraki is rolling out AnyConnect client for MX. Windows L2TP VPN client is pain-in-the-… twitter.com/i/web/status/1… 3 weeks ago
  • one more bug reported cisco.ios.ios_bgp_address_family module github.com/ansible-collec… #ansible #cisco #ios… twitter.com/i/web/status/1… 4 weeks ago
  • #azure canola oil https://t.co/yEj1mCbQ4K 1 month ago
  • My first attempt to fix bug for cisco.ios.ios_bgp_address_family ansible module. PR done. github.com/ansible-collec… 1 month ago
  • RT @C_C_Krebs: This is the real deal. If your organization runs an OWA server exposed to the internet, assume compromise between 02/26-03/0… 1 month ago
  • RT @MirjamKuhne: This morning at #apricot2021 an update from NOGs in the region. https://t.co/kv7tEhszZf 1 month ago
  • RT @hfpreston: A Type 3 LSA walks into a bar and the bartender asks, “Not from the area?” A Type 5 LSA walks into a bar and orders a drink… 1 month ago
  • ansible.com/blog/announcin… 1 month ago
  • Time to refresh home wifi. Moving from #meraki to #Unifi https://t.co/9t6FYIfQfb 1 month ago
Follow @rapappu

Tags

antismap antivirus automation Azure bangladesh BASH BASH Script BDCERT bgp bind ccsp centos CentOS mirror CERT CISA cisco Cyber Security ddos dhaka dhakacom DNS DNSSEC GSM intrusion detectoin system Intrusion prevention system ips IPv6 ISACA junos linux Looking Glass lxc lxc profile lxd mailqueue mailscanner Mail Server mailwatch Meraki mikrotik monitor mpls MPLS L3 VPN mysql My Work network network management nginx NSD observium OpenVPN perl PHP ping postfix Proxy PTA python RANCID Reading RPKI Shell Script sms sms server SNMP SSH Tutorial ubuntu Ubuntu Mirror Server Virtual Box vispan vmware websvn Youtube hack খামাখা

Blog at WordPress.com.