[5 Mins Docker] Create Paste & File Share Site with API Support in Command Line - Linx-Server - NETSEC

Latest

Learning, Sharing, Creating

Cybersecurity Memo

Saturday, April 20, 2024

[5 Mins Docker] Create Paste & File Share Site with API Support in Command Line - Linx-Server

GitHub Project Linx-server is a self-hosted file/media sharing website project which you can use it to develop a temporary website to store your files or texts and share them to the world. I had other posts to introduct similar service such as transfer.sh or microbin. For this project, one of most interesting features is you can use command line to call the APi then upload files, which make it a best alternative for transfer.sh (transfer.sh site is down now). Transfer.sh project is at https://github.com/dutchcoders/transfer.sh, which you will be still able to use it to create your own site. 

In this post, I will show you how to quickly deploy Linx-server to your VPS and how you can use this Linx-server. 


Based on Github, the main features for Linx-server are:
  • Display common filetypes (image, video, audio, markdown, pdf)
  • Display syntax-highlighted code with in-place editing
  • Documented API with keys for restricting uploads
  • Torrent download of files using web seeding
  • File expiry, deletion key, file access key, and random filename options

 Github: https://github.com/andreimarcu/linx-server

Screenshots

Demo Site: 



API page with example commands:


Installation Pre-requirements

Free resources you might need to complete this docker project:


Pre-installed services:

  • Docker, 
    • apt update
    • apt install docker.io
    • apt install docker-compose
    • apt upgrade docker.io
    • mkdir /root/data/docker_data/<docker_name>
  • Docker-Compose (Using Ubuntu OS for the commands)
    • Docker-compose down
    • Optional command : use following command to backup your Docker data. You might need to change your folder name based on your docker configuraiton
      • cp -r /root/data/docker_data/<docker_name> /root/data/docker_data_backup/<docker_name>
    • docker-compose pull
    • docker-compose up -d
    • docker image prune
  • Portainer (Optional)
    • docker volume create portainer_data
    • docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
  • Install some applications: apt install wget curl sudo vim git (Optional)
  • aapanel with Nginx (Optional)
  • Nginx Proxy Manager (Optional)
  • Install screen (Optional)
    • Install screen (Depends on the Linux Distribution if it came pre installed or not) : yum install screen
    • Initiate a Screen : screen or  screen -S <screen name> <command to execute>
    • Detach from the screen : "CTRL+A,D" not "CTRL+A+D"
    • List all the screen currently working : screen -ls
    • Reattach to a screen : screen  -r  <session number> or screen -r <screen name>
    • Kill specific screen: screen -X -S <screen name> quit
    • Kill all screens : pkill screen



Steps


1 Create folders and modify folder permissions

  • mkdir /root/files
  • mkdir /root/meta
  • chown -R 65534:65534 meta && chown -R 65534:65534 files

2 Create configuration file

vi /root/linx-server.conf

bind = 127.0.0.1:80
sitename = NetSec Linx
siteurl = http://<Server IP:Port>/
selifpath = s
maxsize = 4294967296
maxexpiry = 86400
allowhotlink = true
remoteuploads = true
nologs = true
force-random-filename = false
cleanup-every-minutes = 5


Example Options in the configuration file:

OptionDescription
bind = 127.0.0.1:8080what to bind to (default is 127.0.0.1:8080)
sitename = myLinxthe site name displayed on top (default is inferred from Host header)
siteurl = https://mylinx.example.org/the site url (default is inferred from execution context)
selifpath = selifpath relative to site base url (the "selif" in mylinx.example.org/selif/image.jpg) where files are accessed directly (default: selif)
maxsize = 4294967296maximum upload file size in bytes (default 4GB)
maxexpiry = 86400maximum expiration time in seconds (default is 0, which is no expiry)
allowhotlink = trueAllow file hotlinking
contentsecuritypolicy = "..."Content-Security-Policy header for pages (default is "default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; frame-ancestors 'self';")
filecontentsecuritypolicy = "..."Content-Security-Policy header for files (default is "default-src 'none'; img-src 'self'; object-src 'self'; media-src 'self'; style-src 'self' 'unsafe-inline'; frame-ancestors 'self';")
refererpolicy = "..."Referrer-Policy header for pages (default is "same-origin")
filereferrerpolicy = "..."Referrer-Policy header for files (default is "same-origin")
xframeoptions = "..." X-Frame-Options header (default is "SAMEORIGIN")
remoteuploads = true(optionally) enable remote uploads (/upload?url=https://...)
nologs = true(optionally) disable request logs in stdout
force-random-filename = true(optionally) force the use of random filenames
custompagespath = custom_pages/(optionally) specify path to directory containing markdown pages (must end in .md) that will be added to the site navigation (this can be useful for providing contact/support information and so on). For example, custom_pages/My_Page.md will become My Page in the site navigation

3 One Line Command to bring Docker Up

docker run -d -p 80:8080 -v /root/linx-server.conf:/data/linx-server.conf -v /root/meta:/data/meta -v /root/files:/data/files andreimarcu/linx-server -config /data/linx-server.conf


4 Using docker-compose

Example with docker-compose

version: '2.2'
services:
  linx-server:
    container_name: linx-server
    image: andreimarcu/linx-server
    command: -config /data/linx-server.conf
    volumes:
      - /path/to/files:/data/files
      - /path/to/meta:/data/meta
      - /path/to/linx-server.conf:/data/linx-server.conf
    network_mode: bridge
    ports:
      - "80:8080"
    restart: unless-stopped

Using NPM To Handle TLS Certificate

Related Posts:

1 Create DNS Record



2 Configure NPM to do reverse proxy for Linx-Server




3 Enable SSL




4 Modify linx-server.conf file to reflect URL changes

5 Test results

root@ubuntu-linx-server:~# curl -T mytest.txt https://linx.51sec.org/upload
http://linx.51sec.org/1nr5ssmw.txt
root@ubuntu-linx-server:~# cd files
root@ubuntu-linx-server:~/files# ls
1nr5ssmw.txt  2rl0uulo.txt  linx-server.conf  qb8r8hiw.txt
root@ubuntu-linx-server:~/files# 


References



No comments:

Post a Comment