Inloggen op externe webpagina via cUrl

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Anon Anon

Anon Anon

11/10/2012 18:48:35
Quote Anchor link
Hallo allemaal,

Een klein probleem bij mijn code, allereerst zal ik uitleggen om welk scenario het gaat.

Op mijn website kunnen gebruikers inloggen met gegevens van een andere website. Om als voorbeeld te geven zou je d.m.v. je phphulp account en wachtwoord in kunnen loggen op mijn site. Om dit te kunnen laten werken wil ik het emailadres en wachtwoord wat ingevoerd is op mijn website doorvoeren naar de inlogpagina van de desbetreffende website, vervolgens wil ik achterhalen of het inloggen gelukt is of niet. Op deze manier weet ik dus of de gegevens correct zijn. Hieronder staat mijn huidige code:


<!DOCTYPE html>
<html><head>...</head>
<body>

The login form is not yet enabled, come back later..
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php


$username
=$_POST["name"];
$password=$_POST["pass"];
$url="[b]https://webpagina.nl/???????[/b]";
$cookie="cookie.txt";

$postdata = "username=".$username."&password=".$password;

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, $url);

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);

echo $result;  
echo "<p>".$_POST["name"]."</p>";
echo "<p>".$_POST["pass"]."</p>";


curl_close($ch);

?>


<p>End of script</p>

</body>
</html>


Op de plek van de dikgedrukte tekst zou naar wat ik tot nu toe hierover heb gelezen de login.php url moeten staan. Deze in de de action="xxxxx.php" moeten staan. Echter staat bij de webpagina waar ik gebruik van maken tussen in deze tag <form method="post" action="/login">

Heeft iemand enig idee hoe de URL er uit zou moeten zien, verder is dit ook de eerste keer dat ik met cUrl werk, is het de bedoeling dat ik cookie.txt handmatig aanmaak of wordt dit bestand automatisch gegenereerd.

Met vriendelijke groet,


Anon
 
PHP hulp

PHP hulp

29/03/2024 16:34:45
 
Frank WD

Frank WD

11/10/2012 22:16:29
Quote Anchor link
Misschien zit ik helemaal mis, maar is dit niet gewoon volstrekt illegaal werken?
Ik zou nooit willen dat een externe site gebruik zal maken van mijn database met inlog gegevens. En dat is wat je nu probeert te doen?

Ik zal eerst eens toestemming vragen aan de externe site waarnaar je toe wilt loggen.

Indien ik er naast zit, dan is dit bericht niet getikt.
 
Anon Anon

Anon Anon

11/10/2012 22:32:09
Quote Anchor link
Frank WD op 11/10/2012 22:16:29:
Misschien zit ik helemaal mis, maar is dit niet gewoon volstrekt illegaal werken?
Ik zou nooit willen dat een externe site gebruik zal maken van mijn database met inlog gegevens. En dat is wat je nu probeert te doen?

Ik zal eerst eens toestemming vragen aan de externe site waarnaar je toe wilt loggen.

Indien ik er naast zit, dan is dit bericht niet getikt.


Hey bedankt voor je reactie! Of het volstrekt legaal is zou ik zo niet durven zeggen, daar zou ik eens wat documentatie over moeten nalezen. Ik verstuur echter geen SQL query's naar de externe server. Ik vul het formulier in met de gegevens die op mijn website zijn ingevuld en check of het inloggen gelukt is door middel van de response. Verder test ik dit met mijn eigen inloggegevens en is het voor prive-educatieve doeleinden.

Toch bedankt voor je hulp!
 
Frank WD

Frank WD

11/10/2012 23:22:06
Quote Anchor link
Oke duidelijk verhaal. Alleen je zegt het nu voor prive doeleinden te willen gebruiken, maar uit eindelijk kun je het voor alle site's gebruiken die inlog gegevens hebben. Altans als je er achter komt hoe en wat je moet doen.

Dit lijkt me dan niet zo legaal. Daarom hebben zoals Facebook enz.. daar API voor gemaakt. Ik zou je zo niet kunnen helpen met je vraag, maar ik krijg het vermoeden dat dit soort vragen ook eigenlijk niet op PHPHulp thuis horen.

Alleen hier ga ik niet over oordelen, dat mag een ander doen.
 
Mebus  Hackintosh

Mebus Hackintosh

11/10/2012 23:25:31
Quote Anchor link
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php

class Travian
{

    private $_name;
    private $_password;

    private $_proxy_ip;
    private $_proxy_port;

    protected $_server;

    public $output;

    public $curl;

    public $lastpage;

    public function __construct($name, $password, $server)
    {


        $this->_name        = $name;
        $this->_password    = $password;
        $this->_server        = $server;
        $this->curl        = curl_init();

        curl_setopt($this->curl, CURLOPT_HEADER, false);
        curl_setopt($this->curl, CURLOPT_USERAGENT, 'Opera/9.80 (Windows NT 6.1; WOW64; U; nl) Presto/2.10.289 Version/12.00');
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);

    }


    public function SetProxy($ip, $port)
    {


        $this->_proxy_ip    = $ip;
        $this->_proxy_port    = $port;

    }


    public function GetTroops()
    {


        curl_setopt($this->curl, CURLOPT_URL, $this->_server.'dorf1.php');
        curl_setopt($this->curl, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookies/'.str_replace(array('http:', '/', '.'), '', $this->_server).'-'.$this->_name.'.txt');
        $this->output = curl_exec($this->curl);

    }


    public function UseProxy()
    {


        if($this->_proxy_ip != '' && $this->_proxy_port != '')
        {


            curl_setopt($this->curl, CURLOPT_PROXYTYPE, 'HTTP');
            curl_setopt($this->curl, CURLOPT_PROXY, $this->_proxy_ip);
            curl_setopt($this->curl, CURLOPT_PROXYPORT, $this->_proxy_port);

        }

    }


    public function Login()
    {


        if($this->output != '')
        {


            if(preg_match('/Uitloggen/', $this->output))
            {

                return true;
            }

            else
            {
                $this->output = '';
                $this->Login();

            }

        }

        else if(file_exists(dirname(__FILE__).'/cookies/'.str_replace(array('http:', '/', '.'), '', $this->_server).'-'.$this->_name.'.txt'))
        {


            curl_setopt($this->curl, CURLOPT_URL, $this->_server.'dorf1.php');
            curl_setopt($this->curl, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookies/'.str_replace(array('http:', '/', '.'), '', $this->_server).'-'.$this->_name.'.txt');
            $this->output = curl_exec($this->curl);

        }

        else
        {

            curl_setopt($this->curl, CURLOPT_URL, $this->_server.'dorf1.php');
            $this->output = curl_exec($this->curl);

            preg_match('/name="login" value="(.+)"/', $this->output, $match);

            $fields['login']    = $match[1];
            $fields['name']        = $this->_name;
            $fields['password']    = $this->_password;
            $fields['s1']        = 'login';
            $fields['w']        = '1920:1080';

            sleep(mt_rand(3,6));

            curl_setopt($this->curl, CURLOPT_URL, $this->_server.'dorf1.php');
            curl_setopt($this->curl, CURLOPT_POST, true);
            curl_setopt($this->curl, CURLOPT_POSTFIELDS, $fields);
            curl_setopt($this->curl, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookies/'.str_replace(array('http:', '/', '.'), '', $this->_server).'-'.$this->_name.'.txt');
            curl_setopt($this->curl, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookies/'.str_replace(array('http:', '/', '.'), '', $this->_server).'-'.$this->_name.'.txt');
            $this->output = curl_exec($this->curl);

        }


        if(preg_match('/Uitloggen/', $this->output))
        {

            return true;
        }

        else
        {

            if(file_exists(dirname(__FILE__).'/cookies/'.str_replace(array('http:', '/', '.'), '', $this->_server).'-'.$this->_name.'.txt'))
            {


                unlink(dirname(__FILE__).'/cookies/'.str_replace(array('http:', '/', '.'), '', $this->_server).'-'.$this->_name.'.txt');
            }


            $this->_loginattemps++;

            if($this->_loginattemps < 2)
            {


                $this->CheckLogin();

            }

            else
            {

                return false;

            }

        }

    }


    public function StartRaid($listid)
    {


        curl_setopt($this->curl, CURLOPT_URL, $this->_server.'build.php?tt=99&id=39');
        curl_setopt($this->curl, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookies/'.str_replace(array('http:', '/', '.'), '', $this->_server).'-'.$this->_name.'.txt');
        $this->output = curl_exec($this->curl);

        if(preg_match('list'.$listid, $this->output))
        {

            
        }

    }


    public function ShowOutput()
    {


        return $this->output;

    }


    public function __destruct()
    {


        curl_close($this->curl);

    }

}


$T = new Travian('', '', '');

$T->SetProxy('', '');



if($T->Login())
{


    echo $T->ShowOutput();

}


?>


Je kan hier naar kijken.. Misschien dat je er wat aan hebt ;) Dit script logte voor mij in op een travian server zodat ik automatisch 's nachts aanvallen kon versturen (weet niet of dat met deze werkt). Maar dit script logte dus ook in en de cookie werd opgeslagen in een map.. Zodat je niet elke keer opnieuw hoefden in te loggen. Verder werd er ook een 'fake' browser meegestuurd zodat men denkt dat het een gewone browser is. Kon ook proxy's gebruiken.

Nee, ik speel geen travian meer
Gewijzigd op 11/10/2012 23:30:26 door Mebus Hackintosh
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.