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
Simple file uploader
Nothing found.
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / Torrent Trader / v3 Mods Completed

2023-02-24 18:59:18
I cobbled this together because I needed a simpler way for me and a few people to share small files quickly without having to use a service like dropbox or google drive. Put the 3 files in root, create a new folder for the files called uploadedfiles and link or visit yoursite.com/uploader.php. It could be set to only allow admin or vip groups to use it, but I have the delete button set to only allow admin to delete any file and anyone can use it. You can change it as you see fit. I figured I would share it in case its of any use to others. I added this to github, go there for this https://github.com/MicrosoulV3/TTv3-Simple-File-Uploader
uploader.rar
Download
Screenshot 2023-02-24 140255.png
Screenshot 2023-02-24 140255.png

TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Last edited by MicroMonkey on 2023-04-30 04:06:56
2023-02-25 02:13:29
Better version with sanity check and file validator. It makes the error message about being too large much simpler since that error was giving me a hard time haha
uploader.rar
Download

TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Last edited by MicroMonkey on 2023-02-25 06:04:09
2023-02-25 17:18:22
Big thanks MicroMonkey  👍
2023-02-25 18:19:22
For those who have several themes like me, I recommend that you make this small modification
=====================
Pour ceux qui on plusieur themes comme moi je vous recomande de faire cette petite modification

In upload.php look for: / Dans upload.php chercher:
<meta charset="UTF-8">


Replace with: / Remplacer  par:
<meta charset="UTF-8" http-equiv="refresh" content="100" border="none">
   <link rel="stylesheet" type="text/css" href="<?php echo $site_config['SITEURL'];?>/themes/<?php echo $THEME;?>/themes.css" />



Last edited by spiritblue on 2023-02-25 18:20:15
2023-02-25 19:09:51
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.

2023-02-25 19:41:35
I will review that change for my own codebase as it raises a good indication of a potential security hole, I would like to look more into this for myself.

I use a crafty system, but as I see it.. it does not prevent directory traversal attacks. Thanks!


$upload_dir = '/the/absolute/path/to/uploads';
if (isset($FILES['meta_file']['tmp_name']) && strlen($FILES['meta_file']['tmp_name']) > 0) {
   $real_path = realpath($FILES['meta_file']['tmp_name']);
   if (strpos($real_path, $upload_dir) !== 0) {
       $errors[] = 'Invalid file path';
   } else {
       $meta_contents = file_get_contents($real_path); // memory-safe w/ filesize check
       $meta_contents = preg_replace('/[^\x20-\x7E]/', '', $meta_contents);

       // Bdecode and continue POST logic
   }
}
Last edited by STorrents2020 on 2023-02-25 20:10:54
2023-02-25 20:03:03
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
2023-02-25 20:07:41
That is gold. And fully noted. I will keep that in my notes and consult the expression.

And the realpath() string parameter should be an absolute filesystem path for best case from what I understand, perhaps a local constant.

Code updated.
Last edited by STorrents2020 on 2023-02-25 20:10:32
2023-02-25 20:19:13
ok. i'll check that stuff. I was researching and pulling things from all over the place to put that together. I had a basic start point, but had to fiddle for a while changing things, screwing it up, reverting haha because I wasnt quite sure where I wanted to go with it. That is one thing that I didnt put alot of thought into because its mainly just for me and some trusted people, but It makes sense to be correct. Thanks as always for the info
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
2023-02-25 20:27:09
This may be a helpful wrapper


function cleanse_filename(string $string): mixed {
     if (preg_match('/[^\x20-\x7E]/', $string)) {
           return array(
                 'error' => 'Input contains disallowed characters'
           );
     }
     return preg_replace('/[\x00-\x1F\x7F]/', '', $string);
}



if ($check = cleanse_filename($_FILES['meta_file_']['name'])) {
     if (is_array($check)) {
           // bad
     } elseif (is_string($check)) {
           // good
     }
}


Now I have to wonder how far down the pipe this problem exists. For example,


$allowedMetadata = array(
     'application/x-bittorrent' => 'torrent',
     'application/x-switchtorrent' => 'swt'
);


I better consult MSDN too.
Last edited by STorrents2020 on 2023-02-25 20:37:25
2023-02-25 23:59:05
I added in fileUploadScript at the top someplace
$username = $CURUSER['username'];

Then I changed this line.
$uploadPath = $currentDirectory . $uploadDirectory . $username . '_' . basename($fileName);

will add the username to the front of the filename. Just a simple thing
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Last edited by MicroMonkey on 2023-02-26 09:59:06
2023-02-26 23:15:50
for me it works well for uploader.php as such:
<?php
require_once("backend/functions.php");
dbconn(false);
loggedinonly();

stdhead("File Uploader");

if (!$CURUSER || $CURUSER["class"]<"3"){
    show_error_msg(T_("ERROR"), T_("SORRY_NO_RIGHTS_TO_ACCESS"), 1);
}

begin_frame("Partage De Fichier");
if ($CURUSER["class"] >= 3 && $CURUSER["class"]) {


$maxFileSize = 100 * 1024 * 1024; // This sets $maxFileSize to 100 MB. CHANGE THE 100 IF YOU WANT A NEW VALUE. Also Edit fileUploadScript using the same value
$maxFileSizeMB = $maxFileSize / (1024 * 1024); // Convert bytes to megabytes. DON"T TOUCH THIS!

?>  
<!DOCTYPE html>
<html lang="fr">
<head>
   <meta charset="UTF-8" http-equiv="refresh" content="100" border="none">
   <link rel="stylesheet" type="text/css" href="<?php echo $site_config['SITEURL'];?>/themes/<?php echo $THEME;?>/themes.css" />
   <title>Téléchargement de fichier</title>
   <script>
       function validateFile() {
           const fileInput = document.getElementById("fileToUpload");
           const fileSize = fileInput.files[0].size; // file size in bytes
           const maxFileSizeMB = <?php echo $maxFileSizeMB; ?>;
           const maxFileSizeBytes = maxFileSizeMB * 1024 * 1024; // convert to bytes

           if (fileSize > maxFileSizeBytes) {
               const fileSizeMB = Math.round(fileSize / (1024 * 1024));
               alert("File is too large. Maximum file size is " + maxFileSizeMB + " MB. Your file size is " + fileSizeMB + " MB.");
               return false; // prevent form submission
           }

           return true; // allow form submission
       }
   </script>
</head>

<body>
<br/>
<table border="0" cellpadding="3" class="table_table" width="55%" align="center"><tr>
   <td class="table_col1" align="center">
   <form action="fileUploadScript.php" method="post" enctype="multipart/form-data" onsubmit="return validateFile()">
   Partager Le Fichier:
       <input type="file" name="the_file" id="fileToUpload">
       <input type="submit" name="submit" value="Start Upload"><hr/><center>
       <?php
           $maxFileSizeMB = 100; // 100 MB
           $maxFileSizeBytes = $maxFileSizeMB * 1024 * 1024; // convert to bytes
           $fileExtensionsAllowed = ['jpeg','jpg','png','gif','ico','pdf','psd','rar','zip','php','txt']; // These will be the only file extensions allowed. Add/Remove as needed
           echo "<p>Taille de fichier maximale : " . $maxFileSizeMB . " MB</p>";
           echo "<p>Types autorisés: " . implode(', ', $fileExtensionsAllowed) . "</p>";
       ?></center>
   </form>
</td></tr></table>
</body>
</html>

<?php
$uploadDirectory = "/uploadedfiles/"; // Create this directory in your root. chmod 775

function formatBytes($bytes, $decimals = 2) {
 $size = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); // Overkill amounts of conversion, but thorough
 $factor = floor((strlen($bytes) - 1) / 3);
 return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' ' . @$size[$factor];
}

// Scan the upload directory for files
$files = scandir($_SERVER['DOCUMENT_ROOT'] . $uploadDirectory);

// Remove "." and ".." from the list of files
$files = array_diff($files, array('.', '..'));

// Display a list of all files found
echo '<br/><center><color="red">⚞ Les Fichiers Disponible ⚟</color></center><hr/>';

if (count($files) > 0):
?>  
<table cellpadding="5" class="table_table" width="85%" align="center">
<tr>
   <th class="table_head">Supp.</th>
   <th class="table_head">Taille</th>
   <th class="table_head">Nom Du Fichier / Téléchargement</th>
</tr>
<tr>

   <?php foreach ($files as $file): ?>
       <?php if (get_user_class() >= 3): ?>
           <form action="fileDeleteScript.php" method="post" style="display: inline-block;" onsubmit="return confirm('Êtes-vous sûr de vouloir supprimer ce fichier?');">
   <td class="table_col2" align="center"><input type="hidden" name="fileToDelete" value="<?= $file ?>"><button type="submit" name="delete" class="stylebouton" >Supprimer</button></td>
           </form>
<td class="table_col1" align="center">
           <?php endif; ?>
           <?php if (is_file($_SERVER['DOCUMENT_ROOT'] . $uploadDirectory . $file)): ?>
           <span style="font-size: 13px;">(<?= formatBytes(filesize($_SERVER['DOCUMENT_ROOT'] . $uploadDirectory . $file)) ?>)</span></td>
   <td class="table_col2" align="center" width="75%"><?php endif; ?>
           <a href="<?= $uploadDirectory . $file ?>" class="download-link"><?= $file ?></a></td>
</tr>
     <?php endforeach; ?>
</table>
 
<?php else: ?>
   <p><i>..Aucun fichier trouvé!</i></p>
<?php endif; ?>

<br/>
<?php } ?>

<?php
end_frame();
stdfoot();
?>

If it can help! ;)
Last edited by spiritblue on 2023-02-27 22:11:45
2023-02-27 00:50:49
thanks spirit. If its not known, you can move these settings to config.php and remove them from all files. You can just use them as they are and paste them in, or if you want, you can change them to site_config[], but why bother. When I was figuring this out, thats why all those are in each one. Im sure there is more cleanup that can be done since it was put together in pieces.
$fileExtensionsAllowed = ['jpeg', 'jpg', 'png', 'rar', 'zip', 'txt', 'gif','mp4','mp3','wav']; // Allowed filetypes
$maxFileSize = 500 * 1024 * 1024; // Change the first number to desired size eg: 100 = 100MB. Cannot exceed php.ini upload_max_filesize and post_max_size setting
$uploadDirectory = "/uploadedfiles/";

TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
Last edited by MicroMonkey on 2023-02-27 01:20:52
2023-02-27 01:15:50
Do you guys just want my image processing function? It handles absolutely everything, loops all form fields containing a image* name, and gives you a variety of options to convert to if you wish (via radio checkbox or drop-down).

I noticed the array, and that indicates the use for this much more easily. Let me know
2023-02-27 10:02:44
I put this on github since Im sure I'll keep fooling with it, and its just simpler for me https://github.com/MicrosoulV3/TTv3-Simple-File-Uploader
TTv3 Micro Edition
Ubuntu 20.04.6 LTS Server
Mysql Version: 10.3.39-MariaDB-0ubuntu0.20.04.2
PHP Version: 7.4.3-4ubuntu2.20
Apache Version: Apache/2.4.59 (Ubuntu)
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