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

Template help — 2020-11-21 10:11:39 in M-BiTsy Support
Mjay, you should remove all the html markup and set it as helper function for bootstrap cards so users can dynamically change block layouts.

Use single query for counts. Select (select count(*) from somewhere where x = y) as count, other, next from table where y = x

Cache on 1 week countries,languages and such stuff. Raw queries not needed there.

All these forum queries can be joined for less stress. I am on mobile so kinda lazy to write but you can use joins on same table multiple times. Here's example

Select u.*, i.*  from users u left join users i on u.id = i.invited_by where u.id = 1.

This way u get who whole data from user and inviter user in single query.

We have stop doing mysql on college so i will get kinda rusty as we are doing postgree and nosql data schemes and doing everythinng via json for cross compatibility

Make sure to understand indexes in mysql innodb index must be set exactly as where statement in query and you can not use two indexes in single query. But you can join indexes. Index can boost read performance up to 300%, but will slow down writing. So balancing that can really make difference.

There are several books about index weight and sphinx search server to use with sql for more performance

Seems like you have learnt  a lot so i really suggest you to use a framework like laravel and use git for getting a real life working experience.
What will happen if 10.000 bittorrent users are using at any point of time /announce.php without stopping?

There are too many queries, serious rate limiting and network bytes shuffling will be required.

Don't even attempt doing this on big sites and cloudflare. If you do use http method  cloudflare will be contacting you to pay for overusage of the websockets.
"m-jay, post: 68743, member: 20288":

Dont want to use 3rd party code so Was thinking of just adding a question and answer through config if post answer on login does not match config answer it's a fail
This would keep most bots and spiders out

nNot really, all you need is to setup curl and preg_match question field, and set all possible answers to questions via array which will bypass the protection.
— 2020-06-20 13:14:04 in
Doing mvc yourself is an overkill and hardly will ever follow the standards which are predefined in frameworks :D
For simple projects oop or procedural code is always the best.

United is almost the perfect torrent tracker using Laravel, but just look how many people are contributing to it and how simple it is to use https://github.com/HDInnovations/UNIT3D-Community-Edition
recaptcha v3 is privacy invasive and should not be added. It works on same way as hidden recaptcha v2, but collects data and ip score of your user agent / ip / screen resolution / mouse patterns and such.

Hcaptcha.com is way better replacement nowadays.
— 2020-06-14 08:16:24 in
Shouldn't views be used for actual HTML parts of torrents/upload/details/profiles  if this is a MVC structure?

Controllers are only used to return views eg.
public function indexAction()
   {
       View::renderTemplate('Torrent/torrents-upload.html');
   }
Do not create your own salt. It is very concerning and can be brute forced via time based attacks with new amd and intel processors.


Since 2017, NIST recommends using a secret input when hashing memorized secrets such as passwords. By mixing in a secret input (commonly called a "pepper"), one prevents an attacker from brute-forcing the password hashes altogether, even if they have the hash and salt. For example, an SQL injection typically affects only the database, not files on disk, so a pepper stored in a config file would still be out of reach for the attacker. A pepper must be randomly generated once and can be the same for all users. Many password leaks could have been made completely useless if site owners had done this.

Since there is no pepper parameter for password_hash (even though Argon2 has a "secret" parameter, PHP does not allow to set it), the correct way to mix in a pepper is to use hash_hmac(). The "add note" rules of php.net say I can't link external sites, so I can't back any of this up with a link to NIST, Wikipedia, posts from the security stackexchange site that explain the reasoning, or anything... You'll have to verify this manually. The code:

// config.conf
pepper=c1isvFdxMDdmjOlvxpecFw

<?php
// register.php
$pepper = getConfigVariable("pepper");
$pwd = $_POST['password'];
$pwd_peppered = hash_hmac("sha256", $pwd, $pepper);
$pwd_hashed = password_hash($pwd_peppered, PASSWORD_ARGON2ID);
add_user_to_database($username, $pwd_hashed);
?>

<?php
// login.php
$pepper = getConfigVariable("pepper");
$pwd = $_POST['password'];
$pwd_peppered = hash_hmac("sha256", $pwd, $pepper);
$pwd_hashed = get_pwd_from_db($username);
if (password_verify($pwd_peppered, $pwd_hashed)) {
echo "Password matches.";
}
else {
echo "Password incorrect.";
}
?>

Note that this code contains a timing attack that leaks whether the username exists. But my note was over the length limit so I had to cut this paragraph out.

Also note that the pepper is useless if leaked or if it can be cracked. Consider how it might be exposed, for example different methods of passing it to a docker container. Against cracking, use a long randomly generated value (like in the example above), and change the pepper when you do a new install with a clean user database. Changing the pepper for an existing database is the same as changing other hashing parameters: you can either wrap the old value in a new one and layer the hashing (more complex), you compute the new password hash whenever someone logs in (leaving old users at risk, so this might be okay depending on what the reason is that you're upgrading).

Why does this work? Because an attacker does the following after stealing the database:

password_verify("a", $stolen_hash)
password_verify("b", $stolen_hash)
...
password_verify("z", $stolen_hash)
password_verify("aa", $stolen_hash)
etc.

(More realistically, they use a cracking dictionary, but in principle, the way to crack a password hash is by guessing. That's why we use special algorithms: they are slower, so each verify() operation will be slower, so they can try much fewer passwords per hour of cracking.)

Now what if you used that pepper? Now they need to do this:

password_verify(hmac_sha256("a", $secret), $stolen_hash)

Without that $secret (the pepper), they can't do this computation. They would have to do:

password_verify(hmac_sha256("a", "a"), $stolen_hash)
password_verify(hmac_sha256("a", "b"), $stolen_hash)
...
etc., until they found the correct pepper.

If your pepper contains 128 bits of entropy, and so long as hmac-sha256 remains secure (even MD5 is technically secure for use in hmac: only its collision resistance is broken, but of course nobody would use MD5 because more and more flaws are found), this would take more energy than the sun outputs. In other words, it's currently impossible to crack a pepper that strong, even given a known password and salt.
Remove for loop from regex it is performance hungry.

if (preg_match("/(\.php*|\.htm*|\.pl|\.cgi|\.htaccess)/i", $_FILES['file']['name'])) {
exit;
}
Your torrents name table must have full-text index and you have to use mysqli version of torrent trader.
This is SQL injectable.
$torrentid = $_GET['id'];
$stmt = $conn->prepare("SELECT id, announce, info_hash FROM torrents WHERE external = 'yes' AND id = $torrentid LIMIT 1");

[ICODE]yoursite.com/trader-scrape.php?id='1;UPDATE users SET email = "shadows@mail.com" WHERE id = 1'[/ICODE]
Open inspector tool, go to console and see if there is some error log.
After successful ajax request, include window.location.href = '/torrents-edit.php?id=<?= mysqli_insert_id() ?>';
Set redirect in json to be true.

 success: function(data) {
       if (data.redirect == true) {
           // data.redirect contains the string URL to redirect to
           window.location.href = '/torrents-edit.php?id=<?= mysqli_insert_id() ?>';
       }
Looks fancy and way better organized than the default torrent upload, but this requires serious sanitization and security checks.

Here's some suggestions:
1. Use $_SERVER['REQUEST_METHOD'] === 'POST' to verify that request is indeed a post.
2. Use require instead of require_once.
3. if (is_array($_FILES['torrent'])) should be moved as a separate if/else security measure.

$error = '';
// If/else checkings
if (!is_array($_FILES['torrent']))
{
    $error = 'The file contains no array';
}
elseif (empty($_FILES['torrent']))
{
    $error = 'You did not select a torrent file';
}
//Proceed with uploading if no errors are met.
if ($error === '')
{
$insert = $db->query("INSERT INTO torrents (filename, owner, name, descr,  image1, image2, category, added, info_hash, size, numfiles, save_as, announce, external, nfo, torrentlang, anon, last_action)
       VALUES ('" . $torr_saveas . "', " . sqlesc($userid) . ", '" . $torr_name . "', 'Torrent POST description', 'image1', 'image2', 1, '" . get_date_time() . "', '" . $torr_hash . "', '" . $torr_size . "', 3, '" . $torr_name . "', '" . $torr_announce . "', '" . $torr_private . "', 'no', 1, 'no', '" . get_date_time() . "')");
die;
}
else
{
die($error);
}
A lightweight script which I wrote today (Works with modern and older browsers IE 6+). You can create a new .JS, .PHP, and .CSS file to separate those, but I was lazy to do so, so here goes all together.

To include more data, you can change the line: [ICODE]$response .= '<div class="results"><a href="/torrents-details.php?id=' . $i['id'] . '">' . $i['name'] . '</a></div>';[/ICODE]
The hard limit is that search query must have at least 4 characters (to avoid db stressing)

To do a quick test, create a new test.php file

<?php
include 'backend/functions.php';
dbconn();

// This is the PHP side ajax check
if (isset($_GET['ajax']) && $_GET['ajax'] === '1')
{
   if ($_SERVER['REQUEST_METHOD'] === 'POST')
   {
       $searchstr = strtolower(trim($_POST["query"]));
       $search = "MATCH (torrents.name) AGAINST ('".mysqli_real_escape_string($GLOBALS["DBconnector"],$searchstr)."' IN BOOLEAN MODE)";
       if (!empty($_POST["query"]) && strlen($_POST["query"]) >= 4)
       {
           // You can JOIN tables here to get more information about torrents. (But will affect performance)
           $stmt = SQL_Query_exec("SELECT * FROM torrents WHERE $search LIMIT 10");
           $row = mysqli_fetch_assoc($stmt);
       }
   }

   echo '<div class="ls_box">
<div style="text-align: center;border-bottom: 1px solid #eee;padding-bottom: 5px;">Found results for <span style="color: #e6750c; ">' . $_POST['query'] . '</span></div>';
   if ($row)
   {
       $response = '';
       foreach ($stmt as $i)
       {
           $response .= '<div class="results"><a href="/torrents-details.php?id=' . $i['id'] . '">' . $i['name'] . '</a></div>';
       }
   }
   else
   {
       $response = '<div class="results">No results found</div>';
   }
   echo $response;
   echo '</div>';
   die;
}

stdhead('ajax search');
begin_frame('ajax search');
?>

Search torrents: <input type="text" onkeyup="ajaxSearch(this.value)" name="query" />
<div id="ajaxSearchStatus"></div>

<style>
   .ls_box {
       position: absolute;
       background: #fff;
       width: 20%;
       border-bottom: 0;
       border-radius: 10px;
       padding: 10px;
       box-shadow: 0 1px 4px rgba(0,0,0,.1);
       font-weight: bold;
   }
   .results {
       border-bottom: 1px solid #eee;
       padding: 5px;
       word-wrap: break-word;
   }
   .results a {
       color: #111;
       text-decoration: none;
   }
   .results a:hover {
       color: #333;
   }
   .results:hover {
       background: #e6750c3b;
       border-right: 2px solid #e6750c;
   }
</style>

<script type="text/javascript">
   function ajaxSearch(str)
   {
       var xhttp;
       if (str.length < 4) {
           document.getElementById("ajaxSearchStatus").innerHTML= '';
           return false;
       }
       // Modern browser support
       if (window.XMLHttpRequest)
       {
           xhttp = new XMLHttpRequest();
       }
       // Old browser support (IE 6+)
       else
       {
           xhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
       var url = '?ajax=1';
       var params = 'query=' + str;
       xhttp.open("POST", url, true);

       // Send the proper header information along with the request
       xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

       // What to do with the response
       xhttp.onreadystatechange = function()
       {
           if (this.readyState === 4 && this.status === 200)
           {
               document.getElementById("ajaxSearchStatus").innerHTML = this.responseText;
           }
       };
       // Send the post fields
       xhttp.send(params);
       // Until data returned, show custom text
       document.getElementById("ajaxSearchStatus").innerHTML = '<div class="ls_box">Loading data...</div>';
   }
</script>
<?php
end_frame();
stdfoot();


Preview:
Just use SELECT count(id) so that database needs to read only 1 column.

Here's my example with vanilla javascript as I hate jquery.

For a quick test, save as test.php

<?php
include 'backend/functions.php';
dbconn();

// This is the PHP side ajax check
if (isset($_GET['ajax']) && $_GET['ajax'] === '1')
{
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
$username = sqlesc($_POST['username']);
$stmt = SQL_Query_exec("SELECT COUNT(id) as username FROM users WHERE username = $username");
$row = mysqli_fetch_assoc($stmt);

if ($row['username'] < 1)
{
$response = '<font color="green">This username is available</font>';
}
else
{
$response = '<font color="red">This username is not available</font>';
}
echo $response;
die;
}
}

stdhead('username check');
begin_frame('username check');
?>
<form method="post">
Username: <input type="text" onkeyup="usernameCheck(this.value)" name="username" /> <span id="usernameStatus"></span>
</form>

<script>
function usernameCheck(str)
{
// This is just a browser side protection (Check usernames only if username has more than 3 letters)
if (str.length < 3) {
   return false;
}

// Define AJAX XMLHTTP
// Modern browsers
if (window.XMLHttpRequest)
{
   xhttp = new XMLHttpRequest();
}
// I.E 6
else
{
   xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var url = '?ajax=1';
var params = 'username=' + str;
xhttp.open("POST", url, true);

// Send the proper header information along with the request
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

// What to do with the response
 xhttp.onreadystatechange = function()
 {
   if (this.readyState === 4 && this.status === 200)
   {
     document.getElementById("usernameStatus").innerHTML = this.responseText;
   }
 };
// Send the post fields
 xhttp.send(params);
// Until data returned, show custom text
 document.getElementById("usernameStatus").innerHTML = "Processing...";
}
</script>
<?php
end_frame();
stdfoot();
MVC Update (PDO) — 2020-04-30 19:49:59 in M-BiTsy Support
But what is really the point of changing cookies to session? I mean doing this with sessions doesn't really change much to the code other than adding unnecessary additions(Hundreds of sessions files being written every second in /tmp/ folder). The session SID (Should be stored in database, then checked against the user which is logging in with their current session, the session should contain all the info you need to verify if user only logged once, when they performed something and so forth)

This way, its not better than cookies because it lacks data therefore cookies are way more efficient when the site grows big.

Here's an example:
CREATE TABLE sessions (
 sid varchar(32) NOT NULL default '',
 uid int unsigned NOT NULL default '0',
 ip varbinary(16) NOT NULL default '',
 time int unsigned NOT NULL default '0',
 useragent varchar(200) NOT NULL default '',
 anonymous tinyint(1) NOT NULL default '0',
 nopermission tinyint(1) NOT NULL default '0',
 PRIMARY KEY(sid),
 KEY time (time),
 KEY uid (uid),
 KEY ip (ip)
) ENGINE=InnoDB


This way you can expire user from accessing admin panel or moderator panel if 1 hour passed since last login, prevent multiple logins if user has more than 5-10 incorrect logins, you can check if useragent is same as the user which is logging and if another user is already logged and so on.
Just do a double rehashing in account login.

Didn't test it, but should work as intended as it worked in my head :D

if (password_verify($_POST['password'], $row["password")) 
{
/* Add login cookie here
* User has the new hashing method which is working.
*/
logincookie();
}
else
{
if ($row["password"]  === $_POST['password'])
{
    // We are updating the old md5 password or whatever it is.
     $newPassword = password_hash($_POST['password'], PASSWORD_BCRYPT);
     $stmt = DB::run("UPDATE users SET password = ? WHERE id= ?", [$newPassword, $id]);
     logincookie($row["id"], $newPassword, $row["secret"]);
}
else
{
// Password is not correct in either md5 or bcrypt format
logoutcookie();
}
}
MVC Update (PDO) — 2020-04-28 00:08:30 in M-BiTsy Support
"m-jay, post: 68431, member: 20288":

That can be done I'm redoing account controller now with sessions
I have login, logout, recover etc all in one controller just pulling models and views out

With session you can store as much data as you want and it will be always obfucated, the only downside is; session is available only as long as user doesn't close the window and new session file will be created per every site visit.

Also, this increases the server I/O. Therefore, to have 'remember me' option, session must be saved to database because it cant point to user after they leave the site or close the browser.

The cool thing is that you can expire session at exact time you want, without user modyfing values (for example cookies), plus use sessions to logout if more than 1 user is logged to current accound and much more.
Some security enhancements

1. Sanitize all the $_POST field in login and register to prevent XSS.
$_POST  = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);

2. use the identical operator (===) rather than ! or empty()
if ($message === '')
{
   ....
}

3. Use destructor to close active sql connection when execution is completed (this should be automatically done by PHP, but it won't work if database connection is persistent)

4. I'm using a CSRF token (generated via session) for login and register, so no automated requests can be done https://wiki.php.net/rfc/automatic_csrf_protection
Idk mvc module is not worth it if it is not laravel or symphony.
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: 3
  • Members: 0
  • Guests online: 3
  • Comments: 3
  • Messages: 1,728