หน้าเว็บ

วันอาทิตย์ที่ 23 พฤศจิกายน พ.ศ. 2557

CSCamp CTF 2014: Brownies (Web) Write-up

Description:
Hint: think of default files when using source code management systems
Solution:
          

          Open http://178.63.58.69:8083/ and try to login several time but return Username or Password is invalid. I back to read a hint and focus "source code management systems", I maybe mean Github because I ever read some article about this How I stole source code with Directory Indexing and Git, I should request to /.git and found something.


          Try to login by user: ping and password: pong, response "Welcome ping" but not have a flag :/, Next step I look into a http header and found Cookies are so interest. Cookie: type=user; flag=df911f0151f9ef021d410b4be5060972; name=ping 
          In flag value (df911f0151f9ef021d410b4be5060972) after look this, I think this is MD5 because It have a-f0-9{32} and I should decrypt it!! on MD5 Decrypter


          Result is ping, It mean flag=md5(user) right? I back to read .git file and try encrypt "john" string to md5.

MD5 Encrypt: 

root@ubuntu:/tmp# echo -n "john" | md5sum
527bd5b5d689e2c32ae974c6229ff785  -
root@ubuntu:/tmp# 

          I back to read .git again admin: john, and in cookie value have type: user I should edit this value to admin (admin: john), I use Burp Suite to intercept and modify http request. Next step request with normal cookie and click Go.

          Not have a flag, I try to edit the cookie value to Cookie: type=admin; flag=527bd5b5d689e2c32ae974c6229ff785; name=john and click Go!!


         Finally I got a flag.!!

Flag: a012c434d1ec6db911fda4884de14fdd

CSCamp CTF 2014: Elf 1 (Reversing) Write-up

Description:
None
Solution:
          Download binary file and chmod +x binary to execute this file and program will ask for password.


          Open binary file with IDA Pro, Go to Strings tab to find some interest string, I see eWFfcmFnZWw= I think this strings is Base64 encode. Go to submit this decode string but not a flag, Next step I go to find Base64 function in this binary file and I found this.


          Find next interest strings..and I try samir to base64 encode.



           And input this result c2FtaXI= to program.


          I think I got a flag ping-pong you pasamir, Go to submit again but It wrong. :(, I try ping-pong It work. LoL

Flag: ping-pong

CSCamp CTF 2014: PE 1 (Reversing) Write-up

Description:
None
Solution:
          Download and open level1.exe file in windows, It ask for the secret key.


          Next step, open level1.exe with IDA Pro and go to Strings tab. Look around to find some interest string.


          I guess aiiaj and c(eik is a flag, I go to submit aiiajc(eik, OK It work. :O

Flag: aiiajc(eik

วันอังคารที่ 18 พฤศจิกายน พ.ศ. 2557

In-Depth Analysis: MyBB 1.8.1 <= SQL Injection

          หลังจากที่เขียนบทความวิเคราะห์ช่องโหว่ SQL Injection ของ IP.Board ออกมาไม่นานนักทาง Exploit-DB ได้มีประกาศช่องโหว่ SQL Injection และ Cross-site Scripting ของเว็บบอร์ดสำเร็จรูปชื่อดังอย่าง MyBB หรือ MyBulletinBoard ที่มีผู้ใช้งานเยอะไม่แพ้ IP.Board สำหรับเวอร์ชั่นที่มีช่องโหว่ดังกล่าวคือเวอร์ชั่น 1.8.1 หรือต่ำกว่าครับ
          สำหรับช่องโหว่ระดับรุนแรงคือช่องโหว่ SQL Injection ที่เป็นแบบ Error Based มีคนเขียนโค้ดสำหรับเจาะช่องโหว่นี้เหมือนเอาโค้ดจากช่องโหว่ IP.Board มาดัดแปลงเล็กน้อยเลย สำหรับไฟล์ที่มีช่องโหว่คือไฟล์ member.php ตัวแปร question_id ที่จะเกิดขึ้นตอนสมัครสมาชิกครับ
 if($mybb->settings['securityquestion'])
 {
  $question_id = $mybb->get_input('question_id');
  $answer = $db->escape_string($mybb->get_input('answer'));

  $query = $db->query("
   SELECT q.*, s.sid
   FROM ".TABLE_PREFIX."questionsessions s
   LEFT JOIN ".TABLE_PREFIX."questions q ON (q.qid=s.qid)
   WHERE q.active='1' AND s.sid='{$question_id}'
  ");

          จากโค้ดจะเห็นว่ามีการรับค่า $_GET มาใส่ในตัวแปร question_id ผ่านฟังก์ชั่น get_input จากนั้นจึงนำเข้ามารวมกับคิวรี่ SQL ทดสอบการการโจมตีโดย SELECT COUNT(*) FROM mybb_users โดยอ้างอิงโค้ดจาก exploit


          ทำให้ Hacker สามารถใช้ Regular Expression ตัดคำที่ต้องการออกมาจาก Error ที่เห็นได้ เมื่อตามไปดูโค้ดของฟังก์ชั่นที่ครอบ input ไว้นั่นคือฟังก์ชั่น get_input ที่อยู่ในไฟล์ /inc/class_core.php ครับ
 /**
  * Checks the input data type before usage.
  *
  * @param string $name Variable name ($mybb->input)
  * @param int $type The type of the variable to get. Should be one of MyBB::INPUT_INT, MyBB::INPUT_ARRAY or MyBB::INPUT_STRING.
  *
  * @return mixed Checked data
  */
 function get_input($name, $type = MyBB::INPUT_STRING)
 {
  switch($type)
  {
   case MyBB::INPUT_ARRAY:
    if(!isset($this->input[$name]) || !is_array($this->input[$name]))
    {
     return array();
    }
    return $this->input[$name];
   case MyBB::INPUT_INT:
    if(!isset($this->input[$name]) || !is_numeric($this->input[$name]))
    {
     return 0;
    }
    return (int)$this->input[$name];
   case MyBB::INPUT_FLOAT:
    if(!isset($this->input[$name]) || !is_numeric($this->input[$name]))
    {
     return 0.0;
    }
    return (float)$this->input[$name];
   case MyBB::INPUT_BOOL:
    if(!isset($this->input[$name]) || !is_scalar($this->input[$name]))
    {
     return false;
    }
    return (bool)$this->input[$name];
   default:
    if(!isset($this->input[$name]) || !is_scalar($this->input[$name]))
    {
     return '';
    }
    return $this->input[$name];
  }
 }

          การส่งค่าได้ส่งมาเป็น String และไม่มีการกรองค่าที่รับมาทำให้เกิดช่องโหว่ SQL Injection ได้ครับ ตอนนี้แพตช์เวอร์ชั่น 1.8.2 สำหรับแก้ไขช่องโหว่ SQL Injection และ Cross-site Scripting ได้ออกมาตั้งแต่วันที่ 13 พ.ย. ที่ผ่านมา โดยแก้ช่องโหว่ SQL Injection โดยใช้ฟังก์ชั่น escape_string ครอบเข้าไป
$question_id = $db->escape_string($mybb->get_input('question_id'));

          ตามไปดูฟังก์ชั่น escape_string
 function escape_string($string)
 {
  if($this->db_encoding == 'utf8')
  {
   $string = validate_utf8_string($string, false);
  }
  elseif($this->db_encoding == 'utf8mb4')
  {
   $string = validate_utf8_string($string);
  }

  if(function_exists("mysqli_real_escape_string") && $this->read_link)
  {
   $string = mysqli_real_escape_string($this->read_link, $string);
  }
  else
  {
   $string = addslashes($string);
  }
  return $string;
 }

          มีการครอบ mysqli_real_escape_string เข้าไปแล้ว สำหรับใครที่ใช้ MyBB อยู่ก็อัพเดทกันด้วยนะครับ :)

Ref: MyBB 1.8.X <= 1.8.1 Error based SQL Injection
Ref: MyBB 1.8.X - Multiple Vulnerabilities
Ref: MyBB 1.8.2 Released – Security Release

วันจันทร์ที่ 10 พฤศจิกายน พ.ศ. 2557

In-Depth Analysis: IP.Board <= 3.4.7 SQL Injection

          เมื่อวันที่ 9 พ.ย. ที่ผ่านมาได้มีการปล่อย Exploit SQL Injection ของ IP.Board 3.4.7 ซึ่งเป็นเวอร์ชั่นล่าสุด ในเว็บไซต์ของ Full Disclosure และได้มีการ Public โค้ด Python ที่ใช้ในการโจมตีช่องโหว่ดังกล่าวด้วย จึงเป็นที่มาของบทความนี้ครับ
          IP.Board ที่ผมเอามาลองคือเวอร์ชั่น 3.4.6 ครับจากการอ่านโค้ดนั้นเขียนด้วย PHP OOP ไฟล์ที่มีปัญหาก็คือไฟล์ ipsconnect.php ที่ส่งค่าไปยัง ipsMember.php ครับ
/**
 *
 * Map - can modify to add additional parameters, but the IPS Community Suite will only send the defaults
 *
 */
$map = array(
 'login'  => array( 'idType', 'id', 'password', 'key', 'redirect', 'redirectHash' ),
 'logout' => array( 'id', 'key', 'redirect', 'redirectHash' ),
 'register' => array( 'key', 'username', 'displayname', 'password', 'email', 'revalidateurl' ),
 'cookies' => array( 'data' ),
 'check'  => array( 'key', 'id', 'username', 'displayname', 'email' ),
 'change' => array( 'id', 'key', 'username', 'displayname', 'email', 'password', 'redirect', 'redirectHash' ),
 'validate' => array( 'id', 'key' ),
 'delete' => array( 'id', 'key' )
 );

/**
 *
 * Process Logic - do not modify
 *
 */ 
$ipsConnect = new ipsConnect();
if ( isset( $_REQUEST['act'] ) and isset( $map[ $_REQUEST['act'] ] ) )
{
 $params = array();
 foreach ( $map[ $_REQUEST['act'] ] as $k )
 {
  $params[ $k ] = $_REQUEST[ $k ];
 }

 call_user_func_array( array( $ipsConnect, $_REQUEST['act'] ), $params );
}

exit;

          จากโค้ดมีการเรียกใช้คลาส ipsConnect() ที่อยู่ในไฟล์เดียวกันผ่านฟังก์ชั่น call_user_func_array โดยมีการส่งค่าจากตัวแปร $param ซึ่งรับค่า $_REQUEST ที่เก็บไว้ส่งเข้าไปด้วย
          เมื่อนำมาประกอบกันก็จะได้เป็น
call_user_func_array(array(ipsConnect,login),$param); // $param ค่าพารามิเตอร์ส่งเข้าไปในฟังก์ชั่น login

          เป็นการเรียกฟังก์ชั่น login ที่อยู่ในคลาส ipsConnect นั่นเองไล่ไปดูฟังก์ชั่น login กัน
 public function login( $identifier, $identifierValue, $md5Password, $key, $redirect, $redirectHash )
 {
  $member = NULL;
  $statusCode = 'MISSING_DATA';
  $secondsUntilUnlock = 0;
  $revalidateUrl = '';
 
  /* Check */
  if ( in_array( $identifier, array( 'id', 'email', 'username' ) ) )
  {
   $member = IPSMember::load( $identifierValue, 'none', $identifier );
   if ( $member['member_id'] )
   {

          มีการนำค่าที่ $param (idType) ที่รับมาเก็บอยู่ในตัวแปร $identifier จากนั้นเช็คว่าค่าที่ส่งเข้ามานั้นตรงกับค่าใดค่าหนึ่งใน array หรือไม่ด้วยฟังก์ชั่น in_array (idType=id) เมื่อเป็นจริงจึงส่งตัวแปร $identifier และ $identifierValue (id=-1,id[]=-1) เข้าไปในฟังก์ชั่น load ของคลาส IPSMember ในไฟล์ ipsMember.php ครับ
          ตามไปดูฟังก์ชั่น load ในคลาส IPSMember กันครับ
static public function load( $member_key, $extra_tables='all', $key_type='' )
...[snip]...
switch( $key_type )
{
 default:
 case 'id':
  if ( is_array( $member_key ) )
  {
   $multiple_ids = $member_key;
  }
  else
  {
   $member_value = intval( $member_key );
  }
  $member_field = 'member_id';
 break;

          จะเห็นว่าค่าพารามิเตอร์ที่ 3 ($key_type) ที่ส่งเข้ามาในฟังก์ชั่น load นั้นถูกส่งไปทีี่ switch case และตกที่ case id จากนั้นเช็คว่าค่า id ที่รับมานั้นเป็น array หรือไม่ด้วยฟังก์ชั่น is_array ซึ่งการโจมตีที่เกิดขึ้นทำให้เงื่อนไขนี้เป็นจริง และเก็บค่าดังกล่าวไว้ในตัวแปร $multiple_ids ตามไปดูตัวแปรนี้กันครับ
  else if( count($multiple_ids) AND is_array($multiple_ids) )
  {
   $_totalUsers = count($multiple_ids);
   $_gotFromCache = 0;
   $_fromCache  = array();
   
   foreach( $multiple_ids as $_memberValue )
   {
    $member = self::_fetchFromCache( $_memberValue, $_usedTables );
    
    if ( $member !== FALSE )
    {
     $_fromCache[ $member['member_id'] ] = $member;
     $_gotFromCache++;
    }
   }

          เงื่อนไขนี้จะเช็คตัวแปร $multiple_ids โดยฟังก์ชั่น count นับจำนวนใน array และเช็คว่าตัวแปรนี้เป็น array หรือไม่โดยฟังก์ชั่น is_array อีกแล้ว และเมื่อเป็นจริงก็ถูกจับใส่ foreach เพื่อวนเอาค่าในตัวแปร $multiple_ids ออกมาทีละตัวใส่ในตัวแปร $_memberValue และส่งตัวแปร $_memberValue เข้าไปในฟังก์ชั่น _fetchFromCache ครับ ปัญหาอยู่ตรงนี้ครับ ถ้าค่าใน $multiple_ids ไม่ใช่ array จะถูกเข้าฟังก์ชั่น intval ก่อนนำไปคิวรี่ในฟังก์ชั่น _fetchFromCache ($member_value = intval( $member_key );)
          ทดสอบการโจมตีด้วย Firefox + HackBar เมื่อค่าในตัวแปร $multiple_ids ไม่ใช่ array


          สังเกตว่าผมใส่ id=1icheernoom แต่เวลาคิวรี่จะเหลือแค่ 1 เพราะถูกฟังก์ชั่น intval ตัดออกไปเหลือแต่ตัวเลข แต่ถ้าค่าในตัวแปร $multiple_ids เป็น array


          Array ช่องที่ 0 (id[]) คือ  1icheernoom และเมื่อนำไปคิวรี่ยังเป็น 1icheernoom อยู่เพราะไม่ได้เข้าฟังก์ชั่น intval ไว้ ช่องโหว่จึงเกิดขึ้นตรงนี้ครับ


          เมื่อนำคิวรี่ที่ผมไฮท์ไลท์ไว้ไปคิวรี่ใน phpMyAdmin ก็จะได้เป็น


          ผลลัพธ์ของ COUNT(*) FROM members คือ 1 เพราะตอนทดสอบมีแค่ admin คนเดียว และเนื่องจากช่องโหว่นี้เป็น Error based และ IP.Board ได้มีการเก็บ SQL Error ไว้ในไฟล์ /cache/sql_error_latest.cgi (อ้างอิงจากในโค้ด python) ทำให้สามารถไปดึงค่าที่ Error นั้นออกมาได้ นับถือคนเจอบัคนี้เลย ชาบูๆ (=/\=)
          ถึงตอนนี้ Patch สำหรับแก้ไขช่องโหว่ IP.Board <= 3.4.7 SQL Injection ได้ออกมาแล้วครับและแก้ปัญหานี้โดย ถ้าค่าในตัวแปร  $multiple_ids เป็น array ก็ใช้ฟังก์ชั่น intval ครอบไว้ทุกค่าใน array โดยฟังก์ชั่น array_map ครับ
$multiple_ids = array_map( 'intval', $member_key );

          เป็นการส่งฟังก์ชั่น intval เข้าไปทำกับทุกค่าใน array ของตัวแปร $member_key ครับ
Ref : IP.Board version 3.4.7 (latest) suffers from a SQL injection vulnerability.
Ref : IP.Board 3.3.x, 3.4.x Security Update
Ref : 2600 Thailand

วันเสาร์ที่ 8 พฤศจิกายน พ.ศ. 2557

picoCTF 2014: Redacted (Forensics) Write-up

Solve:
You found a letter that may shed light on recent events.
Redacted.pdf:


Hint:
That "super secret access code" looks interesting. I wonder if the info behind the black boxes is really gone for good?
Solution:
          In a letter, I have pdf file and in this file have black boxes to hidden text, It is a flag. when I read a hint, I find some tool to remove black boxes and I found Nitro PDF Professional 9 trial. It work.!!

1. Open PDF File.
2. Edit > Edit



3. Click and drag to remove black boxes, It will show the flag.



Flag: one_two_three_four

picoCTF 2014: Caesar (Cryptography) Write-up

Solve:
You find an encrypted message written on the documents. Can you decrypt it? encrypted.txt
encrypted.txt:
wkhvhfuhwsdvvskudvhlvsqfrayntyqvjpoxeqbmmtlptiktbkf
Hint:
Is there a cipher named the same as the title of this problem?
Solution:
          When I read a hint, I googling to find web tools to Caesar decode online, and I found http://planetcalc.com/1434/.

Input: wkhvhfuhwsdvvskudvhlvsqfrayntyqvjpoxeqbmmtlptiktbkf and click "Calculate".



ROT0 - ROT25
ROT23: thesecretpassphraseispncoxvkqvnsgmlubnyjjqimqfhqyhc <== Interests!!

Flag: pncoxvkqvnsgmlubnyjjqimqfhqyhc

picoCTF 2014: Substitution (Cryptography) Write-up

Solve:
There's an authorization code for some Thyrin Labs information here, along with someone's favorite song. But it's been encrypted! Find the authorization code.
encrypted.txt
encrypted.txt:
kve fqkvsnojfkosd rspe ol hebnebfnep

o deten kvsquvk vaedfl elledkofc
kveane rnqpe fdp qdlbefxfhca bcfod
hqk mfahe kveate f ucommen sz bskedkofc
oz fccoep ks ma tolosd fdp hnfod

o xdsg kvfk asqn bsgenl sz nekedkosd
fne fl gek fl f gfnkvsul hfrxlope
hqk kvorx fl asq fne bfa fkkedkosd
ma gsnpl fne f mfkken sz bnope  
...[snip]...
Hint:
You may want to look at what the relative frequencies of letters in english text are.
Solution:
          When I read a hint and solve, I see a text so interest, frequencies, substitution, That's as may be means substitution cipher. I think I should find online tool to decode some messages in encrypted.txt and I found http://rumkin.com/tools/cipher/cryptogram-solver.php and select some messages (o xdsg kvfk asqn bsgenl sz nekedkosd) input and click "Solve The Cryptogram"


          When I have the results, I select some result to search in google.com and found song lyrics of "The Lion King - Be Prepared", I back to read this problem are favorite song and I think I got a flag. :)


Flag: Be Prepared

picoCTF 2014: Javascrypt (Web Exploitation) Write-up

Solve:
Tyrin Robotics Lab uses a special web site to encode their secret messages. Can you determine the value of the secret key?
Hint:
You may want to learn how to use you browser's JavaScript console.
Solution:
          Because this problem is Web Exploitation, First step I just view-source with Google Chrome (Inspect Element) to find something maybe interest, I found javascript generateKey() function.


Next step, I want to see value in key variable because It is a flag (some variables are random, I think.), I go to http://jsfiddle.net/ and paste generateKey() function in Javascript tab. Add alert(key); under key variable and click "Run".


alert(key) !!!

Flag: flag_3633 (Flag maybe random)

picoCTF 2014: Spoof Proof (Forensics) Write-up

Solve:
The police have retrieved a network trace of some suspicious activity. Most of the traffic is users viewing their own profiles on a social networking website, but one of the users on the network downloaded a file from the Thyrin Labs VPN and spoofed their IP address in order to hide their identity. Can you figure out the last name of person that accessed the Thyrin files, and the two source IP addresses they used?
[Example valid flag format: "davis,192.168.50.6,192.168.50.7"]

PCAP file available here. You can also view it on CloudShark
Hint:
The IP address was changed, but what about the MAC Address?
Solution:
          From hint, I open traffic.pcap with wireshark and focus to IP Address and MAC Address and I found 4 person and one person accessed the Thyrin files (secretfile.txt)


Next step, What MAC Address and IP Address who accessed to secretfile.txt. (MAC: 08:00:27:2b:f7:02, IP: 192.168.50.4) 


I interested in john johnson (MAC: 08:00:27:2b:f7:02, IP: 192.168.50.3)


Go to read problem again: Can you figure out the last name of person that accessed the Thyrin files, and the two source IP addresses they used?
[Example valid flag format: "davis,192.168.50.6,192.168.50.7"]

It mean johnson,192.168.50.3,192.168.50.4

Flag: johnson,192.168.50.3,192.168.50.4