rioastamal.net

Just things inside my head…

Archive for February, 2010

Tutorial: Updating Twitter Status via Shell Script

Posted by rio On February - 9 - 2010

The Goal

Updating twitter status via shell script. The command used to send the HTTP request is POST a.k.a lwp-request (a perl script) that included in most linux distribution.

Twitter Status Update

The Process

  1. Open your text editor i.e. gedit/geany/etc or even vi you are die hard fans of this editor.
  2. Copy and paste code below.

    #!/bin/bash
    #
    TUNAME="lesstalkme"
    TUPASS=""
    TSTATUS=""
    TURL="http://twitter.com/statuses/update.xml"
    TDATA="source=LTME&status="
     
    # print some fancy header :)
    echo "-----------------------------------------"
    echo "         Twitter Status Updater"
    echo " http://www.less-talk-more-example.info/"
    echo "------------------------------------------"
     
    echo -n "Twitter Password: "
    read -ers TUPASS
    echo -e "\nEnter Twitter Status:"
    read TSTATUS
     
    # replace some characters ( I'm too lazy to replace all the characters :))
    TSTATUS=`echo $TSTATUS | sed 's/ /%20/g'` # space => %20
    TSTATUS=`echo $TSTATUS | sed 's/@/%40/g'` # @ => %40
    TSTATUS=`echo $TSTATUS | sed 's/\//%2F/g'` # / => %2F
    TSTATUS=`echo $TSTATUS | sed 's/:/%3A/g'` # : => %3B
    TSTATUS=`echo $TSTATUS | sed 's/#/%23/g'` # # => %23
     
    # now POST the data
    echo ""
    echo -n "Updating status..."
    echo "${TDATA}${TSTATUS}" | POST -C $TUNAME:$TUPASS $TURL | grep $TUNAME > /dev/null
    # check status
    # ------------
    # successfull request always return XML format that containts our username
    # so we grep that to check the status
    if [ $? -eq 0 ]; then
      echo "DONE."
    else
      echo "ERROR."
    fi
  3. Replace TUNAME value with your own username.
  4. Save to somewhere i.e. /tmp directory just for testing.
  5. Name it twitter.sh
  6. Open the shell terminal in GNOME System » Application » Terminal
  7. Go to /tmp directory and give execute permission to the file.
    $ cd /tmp
    $ chmod +x twitter.sh
  8. Execute the file, you’ll be promted to enter twitter password and status.
    $ ./twitter.sh
  9. Fill it and voila!! your twitter status has been updated :).
    Twitter Status

Screencast



Download the Code

twitter.sh.zip via ziddu.com.
Size: 0.69kb
MD5 Checksum: f9d38c632430a617331cc4f8d298fcf1

Source:
http://www.less-talk-more-example.info/2010/02/update-twitter-status-via-shell-script.html

bookmark bookmark bookmark bookmark bookmark bookmark

Patching Bug: Reset Admin Password pada Wordpress <= 2.8.3

Posted by rio On February - 3 - 2010

PERINGATAN!
Artikel ini hanya untuk pengetahuan semata-mata, segala tindakan yang diakibatkan oleh artikel ini bukan merupakan tanggung jawab penulis. Terima kasih.

WP LogoBagi anda yang menggunakan wordpress sebagai engine blog, info berikut ini mungkin sangat berguna untuk anda. Wordpress sebelum versi 2.8.4 memiliki bug Reset Admin Password. Pada versi-versi tersebut seserang tanpa akses privilege apapun dapat dengan mudah mereset password account anda anda hanya dengan mensupply sebuah array pada parameterkey yang ada di query string URL.

Contoh normal link:

http://www.example.com/wp-login.php?action=rp&key=o7naCKN3OoeU2KJMMsag

Link untuk reset:

http://www.example.com/wp-login.php?action=rp&key[]=

Berikut ini adalah potongan code yang menyebabkan bug tersebut.

wp-login.php:
...[snip]....
line +/- 186:
function reset_password($key) {
    global $wpdb
 
    $key = preg_replace('/[^a-z0-9]/i', '', $key)
 
    if ( empty( $key ) )
        return new WP_Error('invalid_key', __('Invalid key'))
 
    $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s", $key))
    if ( empty( $user ) )
        return new WP_Error('invalid_key', __('Invalid key'))
...[snip]....
line +/- 276:
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'login'
$errors = new WP_Error()
 
if ( isset($_GET['key']) )
    $action = 'resetpass'
 
// validate action so as to default to the login screen
if ( !in_array($action, array('logout', 'lostpassword', 'retrievepassword', 'resetpass', 'rp', 'register', 'login')) && false === has_filter('login_form_' . $action) )
    $action = 'login'
...[snip]....
 
line +/- 370:
 
break
 
case 'resetpass' :
case 'rp' :
    $errors = reset_password($_GET['key'])
 
    if ( ! is_wp_error($errors) ) {
        wp_redirect('wp-login.php?checkemail=newpass')
        exit()
    }
 
    wp_redirect('wp-login.php?action=lostpassword&error=invalidkey')
    exit()
 
break
...[snip ]...

» Patching the Bug

Untuk memperbaiki bug tersebut ada dua cara yaitu:

  • Upgrade ke Wordpress 2.8.4, atau
  • Melakukan patch manual

Nah bagi yang malas upgrade wordpress sebaiknya segera melakukan patch secara manual. Berikut ini adalah perubahan pada file wp-login.php sebelum dan sesudah dipatch.

Sebelum patch (cari pada baris sekitar 350-an):

case 'resetpass' :
case 'rp' :
	$errors = reset_password($_GET['key'])
 
	if ( ! is_wp_error($errors) ) {
		wp_redirect('wp-login.php?checkemail=newpass')
		exit()
	}
 
	wp_redirect('wp-login.php?action=lostpassword&error=invalidkey')
	exit()
 
break

Sesudah dipatch:

case 'resetpass' :
case 'rp' :
	if (is_array($_GET['key'])) {
		die("<strong>Hacking detected.</strong>")
		exit()
	}
	$errors = reset_password($_GET['key'])
 
	if ( ! is_wp_error($errors) ) {
		wp_redirect('wp-login.php?checkemail=newpass')
		exit()
	}
 
	wp_redirect('wp-login.php?action=lostpassword&error=invalidkey')
	exit()
 
break

Setelah itu re-upload file wp-login.php ke server anda kembali.

Bagi yang memiliki akses shell ke server anda dapat melakukan patch dengan menggunakan perintah berikut(asumsi file wp-login.php.patch satu direktori).

$ patch wp-login.php -i wp-login.php.patch

Download wp-login.php.patch

Referensi:
http://milw0rm.com/exploits/9410
http://lug.stikom.edu/2010/02/patching-bug-reset-admin-password-pada-wordpress/

bookmark bookmark bookmark bookmark bookmark bookmark