Categories

Archives

Syndication


External content in DIV

4
Oct
Posted at 6:45 am in Internet, PHP

Ever thought of having external content in a DIV without using iframes?

Iframes are ugly and will not validate properly in strict XHTML so therefore a solution for this is needed.
The solution we will use is a very simple PHP function that will grab the content from the page and then display it properly.

So how do we replace that iframe with something else? How can we create an iframe without an iframe?

This solution is widely used as proxy-scripts around the web and it is by far the most simple.

If you’re only aiming to replace an iframe you can do it easily with the file_get_content PHP function.

1
2
3
4
5
6
7
<?php
function displaycontent($url)
{
$content = file_get_content($url);
echo $content;
}
?>

And if you are aiming for a simple proxy-script, you can just add a str_replace command and replace all hrefs with some additional characters:

1
2
3
4
5
function displaycontentproxy($url)
{
$content = file_get_content($url);
$content = str_replace('href="', 'href='proxy.php?url=', $content);
}

A very simple solution to the iframe problem. Solved?

PHP spam script

22
Sep
Posted at 10:05 am in Internet, PHP, Programming

Before you comment, this is a quite lame script, however, it is quite useful as both information and other matters as well. Most people hate spamming but even though you hate it, the source code can be used as something else.

This script will spam a target site with some non existing traffic. You won’t be able to fool web analytics with this script since they will see that you’re from a single IP so there’s no reason to try.

The full source can be viewed at the bottom of this post so you don’t have to copy and extract every piece because of the comments.

Well, let’s get to the point:
In the beginning of the script, we activate error_reporting so we will get some errors written if something goes wrong:

1
2
<?php
ini_set('error_reporting', E_ALL);

After that piece, the configuration follows. Referer, spam-location and the number of hits will be written here:

3
4
5
$referer = "http://thereferersite.com"; // Where the traffic should be sent from
$spamsite = "http://www.thespamsite.com"; // The spam site location
$times = 1; // Number of times you want to traffic spam a site

To continue this, we get the header part. Here we will have the User-agent, which referer we have and which site we have targeted:

6
7
8
$header = "GET / HTTP/1.1\r\nHost: $spamurl\r\n"; // Start of the header
$header .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6\r\n"; // Which useragent. XP, English, Firefox 2.0
$header .= "Referer: $referer\r\nConnection: Close\r\n\r\n"; // Which referer to use and close the connection

When connecting with a socket you need to know which port you should pass through. PHP has a function to do this, called getservbyname. This will most likely use port 80. A full list of which service for which port is found here. We also convert the spam location site to an IP address.

9
10
$port = getservbyname('www', 'tcp'); // Get the port to use when connecting to the www using tcp.
$ip = gethostbyname($spamsite); //Gives you the IP instead of DNS

So now we have finally got to the action part. We start with a for-loop that makes this sequence the number of times we wrote in the configuration part. After that, we create a socket with AF_INET, SOCK_STREAM and SOL_TCP.
AF_INET shows that we are using a IPv4 Internet based protocol.
SOCK_STREAM gives us a reliable, sequenced full-duplex stream which the TCP protocol are based on.
SOL_TCP basically means that we use the TCP protocol.

Then we initiates a connection using socket_connect with our socket we created and the ip address of the target site along with their www port, usually port 80.

A couple of error reports later we find the code “socket_write(..” which is a function that writes the socket with the header we have written before and the length of the buffer. This is followed up by socket_close() which just closes the connection, and then by the randomization part that just makes the script sleep for some milliseconds.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
for ($i = 1; $i <= $times; $i++) { 
  echo "Number: $i\n";
  // Create the socket!
  $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
 
  if ($socket < 0)
    echo "socket_create() failed:\n".socket_strerror($socket)."\n"; // If something fails, what?
  // Connect to site using the socket you created
  $result = socket_connect($socket, $ip, $port);
 
  if ($result < 0)
    echo "socket_connect() failed ($result):\n".socket_strerror($result)."\n";	// If something fails, what?
 
  socket_write($socket, $header, strlen($header));
 
  socket_close($socket); // Closes the socket
 
  $sleep = rand (10, 70); // For randomization
  echo "Sleeping: $sleep\n\n";
  sleep ($sleep);
}
?>

It wasn’t harder then this!
Now you can use this code to create some more funny scripts that are not lame by default (spamming is).

Remember to turn on the sockets extension in your php.ini file if you didn’t have that before. Uncomment the extension=php_sockets.dll line.

The whole source-code is here:

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
<?php
 
ini_set('error_reporting', E_ALL); // Give you all PHP errors reported
 
//
////Some of the configurations
//
$referer = "http://thereferersite.com"; // Where the traffic should be sent from
$spamsite = "http://www.thespamsite.com"; // The spam site location
$times = 1; // Number of times you want to traffic spam a site
 
//
//// Now we'll write the header that should be sent
//
$header = "GET / HTTP/1.1\r\nHost: $siteurl\r\n"; // Start of the header
$header .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6\r\n"; // Which useragent. XP, English, Firefox 2.0
$header .= "Referer: $referer\r\nConnection: Close\r\n\r\n"; // Which referer to use and close the connection
 
//
//// A couple of more facts before the action statrs
//
 
$port = getservbyname('www', 'tcp'); // Get the port to use when connecting to the www using tcp.
$ip = gethostbyname($spamsite); //Gives you the IP instead of DNS
 
//
////Let's spam the site with the $times number of times!
//
 
for ($i = 0; $i < $times; $i++) { 
  echo "Number: $i\n";
  // Create the socket!
  $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);// AF_INET means IPv4 Internet based protocols.
  										     // SOCK_STREAM = sequenced, reliable, full-duplex stream. The TCP protocol is based on this.
										     // SOL_TCP means that TCP will be used.
  if ($socket < 0)
    echo "socket_create() failed:\n".socket_strerror($socket)."\n"; // If something fails, what?
  // Connect to site using the socket you created
  $result = socket_connect($socket, $ip, $port);
 
  if ($result < 0)
    echo "socket_connect() failed ($result):\n".socket_strerror($result)."\n";	// If something fails, what?
 
  socket_write($socket, $header, strlen($header)); // Writes the socket, using the header we wrote earlier and the length of the buffer
  socket_close($socket); // Closes the socket
 
  $sleep = rand (10, 70); // For randomization
  echo "Sleeping: $sleep\n\n";
  sleep ($sleep);
}
?>