Thursday, May 10, 2012

Dos Batch

DOS Batch file to delete folders by date range
@Echo Off
Setlocal EnableDelayedExpansion
:: User Variables
:: Set this to the number of days you want to keep
Set _DaysKept=7
:: Set this to the folder that contains the folders to check and delete
Set _Path=C:\Test1
:: Get todays date
Call :GetDate
Set _yy=%_fDate:~,4%
Set _mm=%_fDate:~4,2%
Set _dd=%_fDate:~6,2%
:: Convert todays date to Julian
Call :JDate %_yy% %_mm% %_dd%
Set _JToday=%_JDate%
:: Set delete date
Set /a _DelDate=_JToday-%_DaysKept%-1
:: Get time format, _iTime will be 0 if 12 hourt clock, 1 if 24 hour clock
:: Delims= is a TAB followed by a space in the next line
:: If you copy this code, you must edit this line
For /F "TOKENS=2* DELIMS=     " %%A In ('REG QUERY "HKCU\Control Panel\International" /v iTime') Do Set _iTime=%%B
If Exist "%temp%\tf}1{" Del "%temp%\tf}1{"
PushD %_Path%
Set _s=s
If %_DaysKept%==1 set _s=
Echo Please wait, searching for folders more than %_DaysKept% day%_s% old
If %_iTime%==0 (Set _Tok=1,4*) Else (Set _Tok=1,3*)
For /F "tokens=%_Tok% skip=4" %%I In ('dir "%_Path%\1*" /AD /OD /TW ^|Findstr /E "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"') Do (
Set _Name=%%K
  If "!_Name:~10!"=="" If %%J==^ (
    Call :GetDate %%I
    Call :JDate !_fDate:~,4! !_fDate:~4,2! !_fDate:~6,2!
    If !_JDate! LEQ %_DelDate% (
      If Exist "%temp%\tf}1{" (
        Echo %%I:%%~fK >>"%temp%\tf}1{"
        ) Else (
        Echo.>"%temp%\tf}1{"
        Echo Do you wish to delete the following folders?>>"%temp%\tf}1{"
        Echo Date       Name>>"%temp%\tf}1{"
        Echo %%I:%%~fK >>"%temp%\tf}1{"
      )) Else (
      Goto :_allFound
      )))
PopD
:_allFound
If Not Exist "%temp%\tf}1{" Echo No Folders Found to delete&Goto _Done
Type "%temp%\tf}1{" | More
Set _rdflag= /q
:_Prompt1
Set /P _resp=Delete All, None, or Prompt for each (A/N/P)?
If /I "%_resp:~0,1%"=="N" Goto _Done
If /I "%_resp:~0,1%"=="A" Goto _Removeold
If /I NOT "%_resp:~0,1%"=="P" (Echo (A/N/P only please)&Goto _Prompt1
Set _rdflag=
:_Removeold
For /F "tokens=1* skip=3 Delims=:" %%I In ('type "%temp%\tf}1{"') Do (
 If "%_rdflag%"=="" Echo Deleting
 rd /s%_rdflag% "%%J")
:_Done
If Exist "%temp%\tf}1{" Del "%temp%\tf}1{"
Goto:EOF
::===================================::
::                                         ::
::   -   S u b r o u t i n e s   -   ::
::                                         ::
::===================================::
:JDate
:: Convert date to Julian
:: Arguments : YYYY MM DD
:: Returns   : Julian date in variable _JDate
:: Usage
::Call :JDate %__GYear% %_GMonth% %_GDay%
:: First strip leading zeroes; a logical error in this
:: routine was corrected with help from Alexander Shapiro
::Code taken from datediff.bat written by Rob van der Woude
::http://www.robvanderwoude.com
Set _JMM=%2
Set _JDD=%3
IF 1%_JMM% LSS 110 Set _JMM=%_JMM:~1%
IF 1%_JDD% LSS 110 Set _JDD=%_JDD:~1%
::
:: Algorithm based on Fliegel-Van Flandern
:: algorithm from the Astronomical Almanac,
:: provided by Doctor Fenton on the Math Forum
:: (http://mathforum.org/library/drmath/view/51907.html),
:: and converted to batch code by Ron Bakowski.
Set /A _JMonth1 = ( %_JMM% - 14 ) / 12
Set /A _JYear1  = %1 + 4800
Set /A _JDate  = 1461 * ( %_JYear1% + %_JMonth1% ) / 4 + 367 * ( %_JMM% - 2 -12 * %_JMonth1% ) / 12 - ( 3 * ( ( %_JYear1% + %_JMonth1% + 100 ) /

100 ) ) / 4 + %_JDD% - 32075
For %%A In (_JMonth1 _JYear1) Do Set %%A=
Goto:EOF
:GetDate
:: This subroutine will always display the same results,
:: for the date independent of "International" settings.
:: This batch file uses REG.EXE from the NT Resource Kit
:: (already installed with WinXP and Vista)
:: to read the "International" settings from the registry.
:: Date is returned as yyyymmdd in variable _fdate
:: Modified from SortDate Written by Rob van der Woude
:: http://www.robvanderwoude.com
::
If NOT [%1]==[] Set Date=%1
If "%date%A" LSS "A" (Set _NumTok=1-3) Else (Set _NumTok=2-4)
:: Delims= is a TAB followed by a space in the next two lines
:: If you copy this code, you must edit these two lines
For /F "SKIP=3 TOKENS=2* DELIMS=     " %%A In ('REG QUERY "HKCU\Control Panel\International" /v iDate') Do Set _iDate=%%B
For /F "SKIP=3 TOKENS=2* DELIMS=     " %%A In ('REG QUERY "HKCU\Control Panel\International" /v sDate') Do Set _sDate=%%B
IF %_iDate%==0 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%date%") Do Set _fdate=%%D%%B%%C
IF %_iDate%==1 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%date%") Do Set _fdate=%%D%%C%%B
IF %_iDate%==2 For /F "TOKENS=%_NumTok% DELIMS=%_sDate% " %%B In ("%date%") Do Set _fdate=%%B%%C%%D
Goto:EOF
FTP Batch
FTP -v -i -s:ftpscript.txt

open example.com
username
password
!:--- FTP commands below here ---
lcd c:\MyLocalDirectory
cd  public_html/MyRemoteDirectory
binary
mput "*.*"
disconnect
bye

Monday, May 7, 2012

Apache 2

Common apache related command
-restart 
/etc/init.d/apache2 restart
 
-reinstall 
apt-get --reinstall install apache2.2-common 

-reinstall configuration files
apt-get -o DPkg::Options::="--force-confmiss" --reinstall install apache2.2-common
 
-fully remove apache
apt-get purge apache2.2-common
apt-get remove --purge apache2 apache2-utils
 
-install apache
apt-get install apache2
   
 
Virtual Host 

vi /etc/apache2/sites-available/adabi
 

        ServerAdmin webmaster@localhost
        ServerName adabi

        DocumentRoot /var/www/adabi
        
                Options FollowSymLinks
                AllowOverride None
        
        
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    
 
 
 
edit /etc/apache2/conf.d/fqdn
ServerName localhost 
 
edit 
/etc/hosts 
 
127.0.0.1       localhost.localdomain   localhost
127.0.0.1       localhost.localdomain   asf
127.0.0.1       localhost.localdomain   adabi
127.0.0.1       localhost.localdomain   open
 
 
activate virtual host :

a2dissite default 
a2ensite adabi
/etc/init.d/apache2 restart
 

Run, Stop, Test, And Restart Apache

 
/usr/sbin/apache2ctl start 
/usr/sbin/apache2ctl stop
/usr/sbin/apache2ctl restart
service apache2 restart 
/usr/sbin/apache2ctl configtest          ::test configuration 

Thursday, May 3, 2012

bash scripting

daily samba backup using crontab
#!/bin/bash
# backup sun01 server : /home/samba_folder 
echo `date` 'backup.sh: START' > /tmp/cron.log
cd /
DATESTAMP=`date +%F`
LIST="/tmp/backuplist_$$.txt"
SOURCE_PATH="/home/samba_folder"
DESTINATION_PATH="/media/backup"
OLDBACKUP_PATH="/home/oldbackup"

#mount -n -t cifs -o rw,username=,password= $DESTINATION_PATH

sleep 5
cat /dev/null > /tmp/bcksun01.out
find /tmp/*.ods  -cmin +200 -type f -exec rm -f '{}' \; 2>>/dev/null
find /tmp/*.csv  -cmin +200 -type f -exec rm -f '{}' \; 2>>/dev/null

#find /home/backup/*.gz -mtime +60 -type f -exec rm -f '{}' \;

set $(date +%d)
if test "$1" = "03" ; then
#   rm -f $OLDBACKUP/sun01.admin.full.tar.gz 2>>/dev/null
#   tar cvfz "$OLDBACKUP/sun01.admin.full.tar.gz" $SOURCE_PATH/admin  2>>/tmp/cron.log >>/tmp/backup.log
   rm -f $OLDBACKUP/sun01.samba_folder.full.tar.gz 2>>/dev/null
   tar cvfz "$OLDBACKUP/sun01.samba_folder.full.tar.gz" $SOURCE_PATH  2>>/tmp/cron.log >>/tmp/backup.log
else
   rm -f $OLDBACKUP/sun01.samba_folder.$1.tar.gz 2>>/dev/null
   find $SOURCE_PATH -depth -type f \( -mtime -2 \) -print > $LIST
   tar cvfzT "$OLDBACKUP/sun01.samba_folder.$1.tar.gz" $LIST 2>>/tmp/cron.log >/tmp/backup.log
   rm -f "$LIST"
fi
  
sleep 1
#umount $DESTINATION_PATH/tn_sql
history -c
echo `date` 'backup.sh: Completed' >> /tmp/cron.log
other backup sample
# use backticks " ` ` " to execute shell command

 # TARIKH=`date +"%Y%m%d_%s"`

mount -t smbfs //131.107.2.20/volume_1/  /home/vol1 -o username=adabi,password=akula
mount -t smbfs //131.107.2.20/volume_2/  /home/vol2 -o username=adabi,password=akula
TARIKH=`date +"%Y-%m-%d"`
TARIKH2=`date +"%Y%m%d"`
TARIKH3=`date +"%Y%m"`
DAY0=`date +"%d"`
WDAY0=`date +"%u"`
YDATE=`date -d '1 day ago' +'%Y%m%d'`
UPDSCRIPT=update$TARIKH.sh
PATCHSCRIPT=patch$TARIKH.sh
SENARAI=/tmp/bcklist.txt
SENARAIF=/tmp/fbcklist.txt

BCK_TNLINUX3=/home/vol1/tnlinux3
echo ${BCK_TNLINUX3}'/tnlinux3.full.tar.gz' > ${SENARAIF}
echo ${BCK_TNLINUX3}'/tnlinux3.artwork.full.tar.gz' >> ${SENARAIF}
echo ${BCK_TNLINUX3}'/tnlinux3.samba.administrator.full.tar.gz' >> ${SENARAIF}
echo ${BCK_TNLINUX3}'/tnlinux3.samba.customer1.full.tar.gz' >> ${SENARAIF}



yesterday date:

date -d '1 day ago' +'%Y-%m-%d'

or

date -d @`echo $((\`date +%s\` – 86400))` +”%Y-%m-%d”
MYSQL :: SQL LEFT JOIN Syntax
SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name

Saturday, April 28, 2012

mysql command

dump data without creating table with condition :
mysqldump -t --max_allowed_packet=1G  --host=ip.add -uuser -ppassword database table --where=sys_date>='2012-02-01'  > /tmp/1.sql

dump data & table :

mysqldump --host=www.pembeda.com -uuser -ppassword database table > /tmp/1.sql

dump data & whole database:

mysqldump --host=www.pembeda.com -uuser -ppassword database > /tmp/1.sql


restore :

mysql -uuser -ppassword
mysql> use database_name
mysql> source /tmp/1.sql
mysql> exit;

Thursday, March 17, 2011

proxy

Proxy :
Why do you Want to Hack School Computers ?

Before going to the actual matter related to the school computers first come to the point that why do you want to hack your school computers.I don’t know why? but I am giving you the common idea i.e what are the common goals that is directly or indirectly associated with the hacking of school compuetrs(I am trying to focus on some simple reasons you may have some special reasons).

Hence in general hacking school computer means

1. To gain administrative power to do some special task(That is not permitted to general user).

2. Students want to use social networking sites like MySpace,Facebook,Orkut..etc, whose access is blocked by default in most school computers.

3. They like to play online games, it may also comes against the school policy.

4. They may like to see pornographic videos or websites,and of course accessing these sites are banned by default.

5. Students also enjoy tempering with grades but administrative power as well as little research is required depending on the security policy of school.

6. In some schools accessing internet is totally banned for student account(Very bad!…unacceptable).

7. It may be obvious some times for us because we are humans and by nature we like to violate the rules.


Now it is little bit clear that why we want to hack our schools computers.Okay lets proceed to the next step –
1. Accessing blocked sites :

This is really very simple.What you have to do is just to use proxy servers.Using proxy server your computer will be connected to the proxy servers but you will be able to accessed blocked sites via proxy server , an intermediate server-computer that will do your work.Here is the list of some websites that will work as a proxy server for you.
Some websites that I had tested on my system and working fine :Just go the website and enter the website address in the url field.

http://www.gumm.org/

http://www.facebookproxy.net/

http://clickfacebook.com/

http://www.theproxyhub.com/

http://www.orkutproxy.info/

http://www.proxyfoxy.com/

Alternative Method : Get the IP address of the website i.e is blocked.Now try to connect using different form of IP address by typing in to your browser’s address bar.Type http and https interchangeably, sometimes it works.You can use the calculator(Click view scientific) to convert the number fr0m decimal to binary or decimal to hexadecimal.
e.g : http://ww.xxx.yy.zz or https://ww.xxx.yy.zz

http://binary_equivalent

https://binary_equivalent

http://hexadecimal_equivalent

https://hexadecimal_equivalent

http://octal_equivalent

https://octal_equivalent

http://dword_value

This method will work if your school computers use DNS(Domain Name System) based protection.So if you can edit the dns mapping files that stores on the system(may be in each computer or centrally managed by the administrator) and used by browsers to look up the domain-IP table;then also you would be able to use blocked websites.
2. Hacking administrator account :

There are many methods to gain administrative power or to access or temper with all the important files on the system.To do this one of the simple method is to use a live cd or pendrive(It is simple.because what you have to do is to download the ISO file and burn it on a CD or you can make your pendrive bootable by following some simple steps) having any linux distribution installed(such as Ubuntu or linux Mint).

Switch on the computer and insert the live bootable cd into the tray.Now booting will be start fr0m live cd instead of hard drive(By default,in special cases press F2 or F10 or F8 to change the booting options so that computer will boot fr0m live cd or pendrive).Since the linux is able to mount all the major file systems format like NTFS,FAT16 or FAT32.Booting andloading will complete within two to five minutes.So after loading the linux into the computer’s RAM you will be able to mount and use or temper with the whole hard disc.Now you are done.Do whatever you want and after shutting down remove the cd fr0m the tray and the windows operating system will work as normal.(Assuming that you didn’t temper with the windows system file..Remember this point and be careful).

What will we do if the BIOS password is installed in the system : In general it is not the case but if it occurs then first try some default BIOS password.You can get the list of Default BIOS password on the internet after getting the name and version of the BIOS,that you will see at the time of booting.You can also try to reset the BIOS by opening the CPU case,Find the lithium Ion battery(having round shape like a silver coin).Now remove the battery and again put it in the same place after 60 seconds.
Some common passwords includes :
AMI cmos Biostar BIOS setup password
Award AWARD_SW lkwpeter AWARD_PW AMI!SW1
j322 h6BB CONDO condo admin 589721
award_? 1322222 256256 ?award Compaq last
AM AMI~ ascend djonet autocad BIOSPASS
AMIPSWD SZYX zbaaaca TzqF t0ch20x

Alternative Method : In old versions of windows you can also use simple commands to gain administrative power at the login promopt.This can be simply done by editing the system files which stores the login information.Follow these steps :

1. At the time of booting press F8 a boot menu will come on the screen,choose DOS.

2. Now you can change your working directory by using cd command.

C:\ cd windows

3. Next,type the command to rename .pwl extensions which contains the login information.

C:\windows>ren *.pwl *.pqr

4. Now restart the computer in normal way and type anything in the password place(when the login promopt will appear)You hacked! and know enjoy the administrative power.(in this method the windows will take this password as actual).
http://blog.sudobits.com/2011/01/27/how-to-install-teamviewer-on-ubuntu-10-10/

TeamViewer is probably the best desktop sharing software for Ubuntu 10.10(Maverick Meerkat).TeamViewer comes with different license terms – One for personal use(which is free) and other for commercial use.TeamViewer is a cross platform application,web based version is also available in commercial license,but here I’ve describe about the free version of the TeamViewer.So TeamViewer is very helpful in providing online help or assistance because one can control or see the others desktop remotely,so it’s also used for various business purposes.On Ubuntu 10.10 you can also use the desktop sharing features provided by empathy but I have better experience with teamviewer.

Installing TeamViewer on Ubuntu 10.10

#1 : Download the *.deb package/installer from the website.

teamviewer for ubuntu 10.10

#2 : Open the downloaded file with Ubuntu Software Center and click on install to proceed.
#3 : Wait for the installation to complete,then go to Applications->Internet->TeamViewer 6.

To share desktop with your friends,send the session ID and password to start a desktop sharing session,after entering the required field click on connect to partner.That’s All..Have Fun with TeamViewer in Ubuntu 10.10.If you have any problems then please share with us..through the comments!!

Saturday, August 8, 2009

Ubuntu server

Setting up the server


  1. install ubuntu 5.04 server
  2. edit /etc/network/interfaces for static ip address by changing the primary interface to:
    •     # The primary network interface
         iface eth0 inet static
             address 158.59.195.113
             netmask 255.255.252.0
             gateway 158.59.192.1
  3. edit /etc/apt/sources.list removing cdrom source at top and uncommenting universe sources
  4. do the apt-get dance (apt-get update and apt-get upgrade)
  5. install the following using apt-get:
    • ssh
    • zip and unzip
    • apache2
    • mysql-server
    • phpmyadmin

Configuring mysql


  1. Point a web brower at http://158.59.195.113/phpmyadmin/
  2. By default, username root with no password is enabled
  3. Login, click on "Change password", and change the password
  4. Click "Databases", fill-in "Create new database" with moodle and click "Create"
  5. Click "Privileges" then "Add a new User"
  6. Add user moodle with all "Data" and "Structure" privileges checked

Configuring Apache Modules


  • As root, run the following:
    • ln -s /etc/apache2/mods-available/proxy.conf /etc/apache2/mods-enabled/proxy.conf
  • Repeat with proxy_connect.load and proxy.load

Configuring virtual hosts


  1. Edit /etc/apache2/apache2.conf, adding a NameVirtualHost line, so that the last three lines of the file look like this:
        # Include the virtual host configurations
       NameVirtualHost 158.59.195.113:80
       Include /etc/apache2/sites-enabled/[^.#]* 
  2. Create a file named azi.conf in /etc/apache2/sites-available with the following:
        
       ServerName linus.yhspatriot.net
       ServerAdmin jeff@elkner.net
       ProxyRequests off
       
       Order deny,allow
       Allow from all
       
       ProxyPass / http://158.59.195.113:8080/
       ProxyPassReverse / http://158.59.195.113:8080/
       ProxyPass /misc_ http://158.59.195.113:8080/misc_
       ProxyPassReverse /misc_ http://158.59.195.113:8080/misc_
       ProxyPass /p_ http://158.59.195.113:8080/p_
       ProxyPassReverse /p_ http://158.59.195.113:8080/p_
       
    
    
       
       ServerName mysql.yhspatriot.net
       ServerAdmin jeff@elkner.net
       ProxyRequests off
       
       Order deny,allow
       Allow from all
       
    
       DocumentRoot /var/www/phpmyadmin/
    
       Options +FollowSymLinks
    
       
               php_flag magic_quotes_gpc On
               php_flag magic_quotes_runtime Off
               php_flag file_uploads On
               php_flag short_open_tag On
               php_flag session.auto_start Off
               php_flag session.bug_compat_warn Off
    
               php_value upload_max_filesize 2M
               php_value post_max_size 2M
       
    
       
               DirectoryIndex index.php
       
       
    
    
       
       ServerName moodle.yhspatriot.net
       ServerAdmin jeff@elkner.net
       ProxyRequests off
       
       Order deny,allow
       Allow from all
       
    
       DocumentRoot /var/www/moodle/
    
       Options +FollowSymLinks
    
       
               php_flag magic_quotes_gpc On
               php_flag magic_quotes_runtime Off
               php_flag file_uploads On
               php_flag short_open_tag On
               php_flag session.auto_start Off
               php_flag session.bug_compat_warn Off
    
               php_value upload_max_filesize 2M
               php_value post_max_size 2M
       
    
       
               DirectoryIndex index.php
       
       
  3. create a sym-link in sites-enabled:
    ln -s /etc/apache2/sites-available/azi.conf /etc/apache2/sites-enabled/azi.conf