Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Saturday, January 27, 2018

[MSCS] Lucky Draw 50pts-Writeup [/WEB]

After competition started about 9:03 min, The first challenge came out with reversing (crackme1) challenge. I just look up that challenge but I can't handle. And I trying to solve that challenge, At this moment in time one of
my team member said to me there is another challenge known as web challenge ( lucky draw 50pt ). I quickly open the challenge link, The challenge description says.




Now, Testing time!
After I opened challenge link.



There is also provide challenge source code. cool!

 





Here is the code logic of that challenge.

In line no 36 > variable "number" is initialize from user input, if user input is not numbers, "number" is set to 0.
In line no 37 > variable "random" is generate by using rand php function between 1000 to 10000.
In line no 38 > compare generated random value with user input number.
If equal we will get the flag!

Here is one condition, you can't predict the random number generated from rand function but you can brute force the certain number ;)

so, let take the your lucky number,
first, I took 2222 as my lucky number and I try to brute force with curl command.
check the command in below pic.




Note ( "gp" is "grep" command )

after 2 min, we can't see the flag

I try to change another number "2222" to "8085".

and I got the flag.



See! we successfully submit the correct value twice within two minutes.



The first challenge that I solved in MCSC2018.
And the first solver team of that challenge, so we got another bonus (1 point ).



I want to say thank you to Ko Min Ko Ko who created this challenge.

Tuesday, July 12, 2016

[Tutorial]Set Custom Error Handler[/PHP]

Hello MSF :bh: 

php programming မွာ error ျဖစ္လို့ error ျပရင္ 
sql error ဆိုရင္

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /var/www/html/index.php on line 12


ဆိုျပီးျပတယ္။

က်ြန္ေတာ္တို့ က custom error handler တစ္ခုကို create လုပ္ျပီး ျပလို့ရပါတယ္။

php မွာပါတဲ့ function တစ္ခုကို ယူသံုးရမွာပါ။

သံုးရမဲ့ function ကေတာ့

set_error_handler("myErrorHandler");


myErrorHandler ဆိုတာကေတာ့ custom function တစ္ခု ျဖစ္ပါတယ္။

example .

<?php
// Creating Error Handler Function
function myErrorHandler($error_level,$error_message,$error_file,$error_line,$error_context){
  
    echo "Error Level : ". $error_level;
    echo "<br>";
    echo "Error Message : ". $error_message;
    echo "<br>";
    echo "Error File Name : ". $error_file;
    echo "<br>";
    echo "Error Line No: ". $error_line;
    echo "<br>";
    echo "Error error context : ". $error_context;
    echo "<br>";
  
}
// set error handler :P
set_error_handler("myErrorHandler");

// print the $test variable that not exists
echo ($test);
// so the error happen

?>


See the pic



photo ေလးကိုျကည့္ျပီးနားလည္မယ္ထင္ပါတယ္။ :hehe:

ေအာက္ php code ေတြကေတာ့
error msg ေတြကို www-data@localhost.localdomain mail ကို send လုပ္ေပးမွာျဖစ္ပါတယ္
( localhost မွာ စမ္းထားတဲ့ အတြက္ www-data@localhost.localdomain mail ကို ထဲ့ထားတာျဖစ္ပါတယ္ )



<?php
error_reporting(0); // Do Not Show any error in web page.

// Error Handler Function Create
function myErrorHandler($error_level,$error_message,$error_file,$error_line,$error_context){

   $msg = "Error Level : ". $error_level;
   $msg .= "\nError Message : ". $error_message;
   $msg .= "\nError File Name : ". $error_file;
   $msg .= "\nError Line No : ". $error_line;
   $msg .= "\nError context : ". $error_context;
   $to = "www-data@localhost.localdomain";
   $subject = "[Error Happen]";
   mail($to, $subject, $msg);


 
}
// set error handler :P
set_error_handler("myErrorHandler");

// print the $test variable that not exists
echo ($test);
// so the error happen
echo "Hello";
?>


ဒါဆိုရင္ error msg ေတြကို ေအးေအးေဆးေဆး ထိုင္ျကည့္ေနေတာ့ :P


To see error msg in localhost :hehe:  ( tested in Kali Linux )


tail -f -n 0 /var/mail/www-data

စမ္းျကည့္ရေအာင္ ။  :hehe:

Web page မွာ error မျပပါဘူး
Hello ဆိုတဲ့ စာေတာ့ လာျပပါတယ္
User က Error message ကို ျမင္လိုက္ရမွာ မဟုတ္ပါေတာ့ပါဘူး။

web admin ကသာ error msg ကို ျမင္ေတြ့ရမွာျဖစ္ပါတယ္။




ဒါဆိုရင္ error ကို troubleshoot လုပ္လို့ရပါျပီ။
Normal Error လား
Attacker တစ္ေယာက္ရဲ့ attack ျပုလုပ္မွုေျကာင့္ တက္တဲ့ error လားဆိုျပီး :P :P

:bh: :bh:

နားမလည္ တာရွိလို့ရွိရင္ ေမးလို့ရပါတယ္ဗ်ို့။

:bh: :bh:


Take Care!

Tuesday, November 10, 2015