Deta – free micro server for dev

Tram Ho

Preamble

Sometimes we need a simple web server, public to the internet to perform some miscellaneous tasks, or to host some files when needed. However, as a “poor” dev/pentester, having a visa card to register for free cloud of Google, AWS, Oracle is sometimes a big problem. Just kidding, in this article I will introduce Deta – a tool that allows you to quickly create a micro-website/API and publish it to the internet. Here we go~

Deta

image.png

https://deta.sh is a free personal Cloud tool that allows us to build applications, prototypes and then publish to the internet quickly.

Deta comes with:

  • Deta Base : NoSQL database (same as MongoDB)
  • Deta Micros : Allows you to deploy your application to the internet (like Heroku). Deta lets you create as many micros as you want
  • Deta Drive : Allows file storage (same as Google Drive and AWS S3)

Deta currently supports the following languages: Python , Node.js , and Golang . For each language, Deta also supports micro-frameworks such as Python’s FastAPI or Flask .

As an example, I will build a simple application for pentester as follows:

  1. Allows uploading files by arbitrary URL and MIME Type. For example: access the link: ” https://myfakeserver.com/aaa.png ” but return the content as alert(origin) and the mime type is javascript (not an image file like PNG).
  2. Let the user directly fill in the file content.
  3. Allows deleting files.

Setting

All user manuals (complete and detailed) are available at https://docs.deta.sh/docs/home

First of all, we need to register an account. The management screen is located at: https://web.deta.sh/home

Then we download the Deta CLI and log in:

then create a new micro with python framework:

Check out the newly created file:

Right at this step we can run deta deploy and our app will be deployed to the URL above. Too fast too dangerous:

image.png

We can also install additional libraries, create a requirements.txt file and enter the names of the libraries, here we will need Flask and Deta.

Every time you fix the code, remember to deta deploy to push the code up

Backend

Modify the main.py file as follows, because the code is also quite short with 88 lines and simple, so I will not go into each step but just explain some important positions.

In this paragraph we need to create Project Keys (similar to API key) in the interface below, drive and db are objects that help us interact with the database and drive:

image.png

The route part, we will create a route to catch all (catch all requests) and then check:

  • If path index => go to upload page.
  • If it’s path delete => go to file delete page
  • Otherwise, the default is to process and return file content (if any exist).

Deta has also provided us with methods to interact with the DB:

Used to insert a record into the DB. We will save the path (to check if there are duplicates), filename is randomly generated by uuid , mime entered by the user or taken from the uploaded file. The data in the DB will have the following form:

used to retrieve data, can query exactly or follow a syntax close to MongoDB: https://docs.deta.sh/docs/base/queries .

Used to delete files based on key. You can also interact directly through the interface at https://web.deta.sh/home:

image.png

Very simple, right? Interacting with Drive is also quite similar:

Drive also has an intuitive interface:

image.png

Frontend

No colors, flowers, pure HTML interface, no CSS

It’s Demo Time

Run deta deloy and see the result: https://8r8cjf.deta.dev/

Limit

Of course, with a Free service like this, it will come with some main limitations:

  • The micros are actually running on Lambda so boot time (after sleep) can be slow.
  • RAM is only 512MB.
  • Requests will time-out after 10 seconds, so processes cannot run for a long time.
  • If you do not upload to Drive, you can only upload to the /tmp/ .
  • The drive has a capacity of 10GB.
  • Library up to 250MB, source code up to 250MB.

More details at: https://docs.deta.sh/docs/micros/about

But for the purpose of prototype and demo, this is still OK la

Also what else?

Deta also provides some pretty useful utilities:

  • Deta Crons allows to run tasks periodically (like cronjob in Linux).
  • Deta Visor allows us to view the request/response log to the microphone and the error log.
  • Allow custom subdomain (for example: https://myserver.deta.dev/ ) and own domain, too convenient for dev brothers to make wedding invitation web

image.png

Conclude

Hope everyone makes good use of Deta and has a lot of good ideas

Share the news now

Source : Viblo