Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
User Posts

Go to Profile

Ratio freezes at 0 — 2023-03-18 17:09:39 in v3 Support
You can track stats on public torrents.

You need the following to occur:

1.) announce should be your local announce
2.) announce-list[0] - should be your local announce

Then seeders/leechers will show accuratley, however it would not display the seeders/leechers of other trackers inside of the torrents table.
Yep,

filter_input/filter_var or even regex good to get rid of the control characters.

For most inputs they should be restricted to

[\x20-\x7E]

For things like name of torrents

If your going to allow comments in areas you can expand that to allow some of the control characters e.g:

Newline
Tab

I have had success bypassing many firewalls using the non breaking space as people tend to only try restricting characters that are printable from the [\x20-\xFF] range
I would recommend reviewing the delete code, i am not sure that is safe, it would be vulnerable to something like:

./../../etc/passwd

If you had a extension at the end then it still wouldn't be safe as most of PHP's functionality isn't protected against null byte e.g: %00

In C the null byte is used to determine where the end of a string would be so if you had something like:

include('data/' . $_POST['file'] . '.jpg');

Then you would be able to do something like

myfile.exe%00 and that would chop of the .jpg

i would personally do this:

$uploadDirectory = realpath("/uploadedfiles/");
if ($uploadDirectory === false) {
  show_error_msg("Error", "Cannot determine data directory.", 1);
}

and change this:

$filePath = $_SERVER['DOCUMENT_ROOT'] . $uploadDirectory . $fileToDelete;

to

$filePath = realpath($uploadDirectory . $fileToDelete);
if (0 !== strpos($uploadDirectory, $filePath)) {
   show_error_msg("Error", "Possible hacking attempt, trying to leave upload dir.", 1);
}

but still would recommend doing more validation on $fileToDelete, but should give you a better indication of what is needed.

ACL Query — 2022-08-13 15:01:38 in General Chat
There is alot of different ways to go about this, no idea what the best approach would be, but i always felt the permission system in TT was too weak, i can remember when people would use things such as:


if (get_user_class() >= 3) {
}


Which works well until you add a new user class and then all of a sudden the logic won't work as expected because the new group_id is greater than the admins group_id so any static code like this should certainly be a no go.

Like i described in the shoutbox the other day some of the main issues i felt was hard to resolve was say you have a uploader class 4 which donated and you can't display them as a vip/donator because they are assigned to the uploader class and not a vip class.

A very simple approach may be to just have two permission sets:

1.) Group permissions
2.) User permissions

They are both the same permissions that exist in groups with the following conditions:

1.) Group permission sets the default policy.
2.) User permission will override the group policy either way so you could do something like:


if ($myGroup->can_upload === 'no' && $myUser->can_upload === 'no') {
   // Group & User not allowed to upload.
   $allowed = false;
} elseif ($myGroup->can_upload === 'yes' && $myUser->can_upload === 'no') {
  // Group allowed to upload but user not so prevent uploading.
  $allowed = false;
} else {
  // other results should match:
  // group can upload and user can upload
  // group can't upload but user can.
  $allowed = true;
}


What do you think?
Code TidBits — 2022-07-16 06:41:10 in Support & Suggestions
No worries.

Yeah you can use SPL autoload for that, in the past i used a interface to ensure that plugin files always contained certain methods e.g: install, uninstall but alternatively you may be interested in a hook system.


<?php

class Hook
{
   protected $hooks = [];

   public function register(string $hookName, callable $callback)
   {
       $this->hooks[$hookName][] = $callback;
   }

   public function __call($method, $params)
   {
       if (! is_string($method)) {
           throw new InvalidArgumentException('$method should be typeof: string');
       }
       if (array_key_exists($this->hooks, $method)) {
           foreach ($this->hooks[$method] as $hook) {
               call_user_func_array($hook, $params);
           }
       }
   }
}

// Initialise hook system globally.
$hook = new Hook();

// Register potential hooks at start up.
$hook->register('onSignup', function($username, $password) {
   // Do something interesting...
});

// At locations call hooks.
$hook->onSignup('mostvotedplaya', 'foobar');

Code TidBits — 2022-07-15 11:37:47 in Support & Suggestions
How many BEP's are you using?

I was actually thinking a smart idea of the library im working on is to make little plugins to auto detect them.
it's probably better to use

pieces & piece layers like


           $v1 = isset($buffer['pieces']);
           $v2 = isset($buffer['piece layers']);
           if ($v1 && $v2) {
               $type = 'hybrid';
           } elseif ($v1) {
               $type = 'v1';
           } elseif ($v2) {
               $type = 'v2';
           } else {
               $type = 'neither';
           }
There alot of improvements in the v2 spec.

The .torrent file can be alot smaller than a std v1 one.

In v1 pieces are all 20 bytes long.

In v2 pieces are 32 bytes long, if a given piece is smaller than the given piece length then it will not have a entry in the piece layers field.

In theory if torrent clients stopped using sha1 and started using sha256 when creating .torrents then you could easily convert v1 torrents to v2.

The only time v2 would become mainstream is if big open trackers enforced it.
What debugging have you done? You have posted a image showing a broken image link, have you not checked the field to see if there is something there? there are times using external images are bad as they can be blocked based on referrer / http authentication.
It appears that way:


root@ks26796:/tmp# php benchmark.php
0.0027430057525635
0.0027451515197754
root@ks26796:/tmp# php benchmark.php
0.0028049945831299
0.0026988983154297
root@ks26796:/tmp# php benchmark.php
0.0027830600738525
0.0027620792388916
root@ks26796:/tmp# php benchmark.php
0.0028049945831299
0.0027379989624023
root@ks26796:/tmp# php benchmark.php
0.0027430057525635
0.0027399063110352

$code = rand(100000, 999999);


You could use something like that to create a 6 digit random code, i think e-mail probably the cheaper option or just use a 2fa system like Google Authenticator, but if you want to roll your own then i would generate some conditions which would trigger the system, you would need to use some permanent storage to do this.
A finished result would look something like:


<?php

// Load Libs.
include('/var/www/html/1xbtc/System/Library/BitTorrent/Bencoder.php');
include('/var/www/html/1xbtc/System/Library/BitTorrent/Bdecoder.php');

$bencoder = new \System\Library\BitTorrent\Bencoder();
$bdecoder = new \System\Library\BitTorrent\Bdecoder();

// Parse torrent.
$torrent  = file_get_contents('test.torrent');
$decoded  = $bdecoder->decode($torrent);

// Bencode info dictionary.
$infoField = $bencoder->encode($decoded[1]['info']);


/**
* Convert PEM to DER.
*
* @param  string   $buffer The contents of the PEM.
* @return stdClass
*/
function convertToDer(string $buffer) : stdClass
{
   $result = new stdClass();
   if (preg_match('/^[-]{5}BEGIN CERTIFICATE[-]{5}([\S\s]+)[-]{5}END CERTIFICATE[-]{5}$/', $buffer, $m)) {
       $result->status = 'success';
       $result->result = base64_decode($m[1]);
   } else {
       $result->status = 'failure';
   }
   return $result;
}

// Verify private key.
$pKey = file_get_contents('server.key');
$pKey = openssl_pkey_get_private($pKey, 'howarth');

// Sign info.
openssl_sign($infoField, $signature, $pKey);

$buffer  = file_get_contents('server.crt');
$convert = convertToDer($buffer);
if ($convert->status === 'success') {
   $dict = $decoded[1];
   $dict['signatures']['link.m2g'] = [ // link.m2g would be Common Name in reverse DNS notation.
       'certificate' => $convert->result,
       'signature'   => $signature
   ];
   $dict = $bencoder->encode($dict);
   file_put_contents('output.torrent', $dict);
} else {
   print("Something went wrong.\n");
}

<?php

/**
* Convert PEM to DER.
*
* @param  string   $buffer The contents of the PEM.
* @return stdClass
*/
function convertToDer(string $buffer) : stdClass
{
   $result = new stdClass();
   if (preg_match('/^[-]{5}BEGIN CERTIFICATE[-]{5}([\S\s]+)[-]{5}END CERTIFICATE[-]{5}$/', $buffer, $m)) {
       $result->status = 'success';
       $result->result = base64_decode($m[1]);
   } else {
       $result->status = 'failure';
   }
   return $result;
}

$buffer  = file_get_contents('example.crt');
$convert = convertToDer($buffer);
if ($convert->status === 'success') {
   $dict['signatures']['link.m2g'] = [
       'certificate' => $convert->result,
       'signature'   => ''
   ];
} else {
   print("Something went wrong.\n");
}


To generate the signature you need to Bencode the info dictionary and then pass that to openssl_sign the raw output is the answer.
I did some testing on this earlier and seems my earlier assumptions was wrong.

The tool only generated two fields for me:

signatures.domain.certificate - See 1
signatures.domain.signature  - See 2

1.) This is a binary string:

The certificate file would be something like:

-----BEGIN CERTIFICATE-----
(Content Here is Base64 encoded)
-----END CERTIFICATE-----

DER format would be the base64_decoded data of the certificate (i think.)

2.) This is also a binary string:

I am guessing you need to use openssl_sign here.
As i said in the previous post this is wrong:


 'signature' => sha1($signature)


At minimum it should include the info dictionary.

 

$dict = []; // decoded .torrent
$dict['signatures']['com.bittorrent'] = [
   'signature' => sha1(Bencode($dict['info']))
];


The example provided shows


"com.bittorrent": {
           "certificate": optional, DER encoded x.509 certificate,
           "info": { ... } optional,
           "signature": signed data = info + sig info if present,
       }


if you add the info field then needs to be


$info = []; // It's a dictionary...
$dict = []; // decoded .torrent
$dict['signatures']['com.bittorrent'] = [
   'info'           => $info,
   'signature' => sha1(Bencode($dict['info']) . Bencode($info))
];
$dict = Bencode($dict); // Encode entire torrent.

<?php

function reverseDNS(string $hostname) : ?string
{
   if (! preg_match('/^[a-z0-9][a-z0-9\.\-]*[.][a-z]{2,}$/', $hostname)) {
       return null;
   }
   $pieces = explode('.', $hostname);
   $pieces = array_reverse($pieces);
   return join('.', $pieces);
}

echo reverseDNS('bittorrent.com') . "\n";


They recommend to use reverse dns, this would return com.bittorrent, also as stated in the BEP

Quote:
signature - Required byte string. This is the RSA signature of the concatenation of the torrent's info dictionary and the signature's info dictionary (if present).
vip — 2022-06-13 19:07:07 in v3 Mods Requests
That code looks awfully bad to read.
Announce Class — 2022-05-30 22:27:52 in Downloads & Updates
For me v2 of the protocol is overly complicated, it's been a few years since i was active around the net consistently so im not really sure if many people using it or not.

The detected hashing collision was always going to occur at some point, i suspect in the wild mainly on public trackers they encountered this issue alot.

Alot of trackers fail to validate .torrents properly, TT was just as bad but the problem is that all the source codes derived from each other.

I did some testing ages back and it's possible to upload .torrents with 0 files and quite possibly alot of other junk.

I highly recommend just sticking with v1 until the code is to a good standard.

I started working on a version 3 of TT years back and used validations such as:

Ensures info dictionary is properly sorted.

$encoded = $this->bencoder->encode($dict['info']);
$matched = strpos($data, $encoded);
if ($matched === false) {
    throw new Exception('Bdec->Benc mismatch.');
}


Parsing the pieces field.

           if (isset($dict['info']['pieces'])) {
               if (! is_string($dict['info']['pieces'])) {
                   throw new Exception();
               }
               $length = strlen($dict['info']['pieces']);
               if ($length === 0) {
                   throw new Exception();
               }
               if ($length % 20 !== 0) {
                   throw new Exception();
               }
               $pieces = [];
               for ($i = 0; $i < $length; $i += 20) {
                   $buffer = substr($dict['info']['pieces'], $i, 20);
                   $buffer = bin2hex($buffer);
                   $pieces[] = $buffer;
               }
           } else {
               throw new Exception();
           }


Once you have decoded the filesize, piece size you can compute how many hashes there should be with something like:


$expectedPieces = ceil($length/$pieceLength)*20;
$actualPieces       = strlen($dict['info']['pieces'])/20;
Announce Class — 2022-05-30 17:08:24 in Downloads & Updates
Yep


info_hash
peer_id
ip
port
uploaded
downloaded
left
event


These are the only fields that you can guarantee are supported by all torrent clients. The only reason the passkey system works is because it's apart of the announcement url.

I always wanted to build a system that doesn't use the database for the announce/scrape, instead it would use the file system:


root@ks26796:/opt/tracker# tree
.
├── torrents - (Holds valid infohashes)
│   └── 023f50e51320151508739a2ff1350dcc4a2bc333
└── users - (Holds valid passkeys)
   └── 48248-dsja38l-aiidad3-394dak


in torrents/<infohash> you can store each indivudal peer there, once the data is validated theres no reason why you can't just serialise the get request and dump it in the file.

if a torrent is deleted/banned you would remove the torrents/<infohash> directory
if a user is deleted/changed passkey then remove users/<passkey>

i certainly think is_file would be faster than a table scan in the database etc.
Blank coment — 2022-05-30 15:24:13 in v3 Support
I think the best approach would be:


$body = trim($body);
if (empty($body)) {
   // Handle error here...
}


Because hitting spacebar a few times would bypass strlen check.
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 2
  • Members: 0
  • Guests online: 2
  • Comments: 3
  • Messages: 1,728