Skip to content

Instantly share code, notes, and snippets.

@CypherpunkSamurai
Created April 7, 2022 17:29
Show Gist options
  • Select an option

  • Save CypherpunkSamurai/7b476aef9d42fc29fe8a904a91039e85 to your computer and use it in GitHub Desktop.

Select an option

Save CypherpunkSamurai/7b476aef9d42fc29fe8a904a91039e85 to your computer and use it in GitHub Desktop.
Mega.nz Download API

MEGA Downloader

MEGA.nzmega.nz

We make secure cloud storage simple. Create an account and get 50 GB free on MEGA's end-to-end encrypted cloud collaboration platform today!

Mega.n Downloader Script

A script to download file from Mega.n and read it. (Using PHP)

Features

  • Get file details and information
  • Download the file
  • Read file and Decrypt it

Tasks

step 1: make api call to mega api server get info about the file with download link api return filename,filesize,download link filename is encrypted string

step 2: we download the encrypted file using the url returned in step 1 api response

step 3: after download decrypt the file

Sample MEGA Link

https://mega.nz/#!GF9mCC5A!yrZMIgVlNok_wE6Vl2130sTJKOGTKgvxpPjSVOwVz1Y1

File ID: GF9mCC5A

File decrypt key: yrZMIgVlNok_wE6Vl2130sTJKOGTKgvxpPjSVOwVz1Y1

Sample API Response

[0] => stdClass Object
(
    [s] => 4
    [at] => gELEbMQ0rg3kEyC9sUtlORwYuQ_Kp19OMXm0Ju-u_enARPeJSc0DleBpdw_GjBIcFt8YHP_Jr_-r2Q7kywUt0w
    [msd] => 1
    [tl] => 0
    [g] => https://gfs270n062.userstorage.mega.co.nz/dl/NcL3FDKCLMnG7gLizKAJNyhehZe5cNgHTl5h0ceS0DHL8okSJCeRPnbvBWgz63oA1m-PTVG24rSrAK5U47pPuFcxMXbVvHpwXvSiuhUyfHnXvu9vI_pHLBYUZfsbJA
)

File link at top object is expired!

MEGA API Structure

  • at=attributes means contains filename etc
  • s=size of file
  • g=dl link
  • at=file attributes it may contain other info also not only filename

Call API Using CURL

File ID: GF9mCC5A

API URL: https://g.api.mega.co.nz/cs

curl -X POST -d '[{"a":"g","v":2,"p":"GF9mCC5A","ssl":2,"g":1}]'  -v https://g.api.mega.co.nz/cs

Response:

* About to connect() to g.api.mega.co.nz port 443 (#0)
*   Trying 31.216.147.135...
* Connected to g.api.mega.co.nz (31.216.147.135) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate:
* 	subject: CN=*.api.mega.co.nz,OU=PremiumSSL Wildcard,O=Mega Limited,STREET="15, Pwc Tower, 188 Quay Street,",L=Auckland,ST=Auckland,postalCode=1010,C=NZ
* 	start date: Dec 11 00:00:00 2017 GMT
* 	expire date: Dec 10 23:59:59 2020 GMT
* 	common name: *.api.mega.co.nz
* 	issuer: CN=COMODO RSA Organization Validation Secure Server CA,O=COMODO CA Limited,L=Salford,ST=Greater Manchester,C=GB
> POST /cs HTTP/1.1
> User-Agent: curl/7.29.0
> Host: g.api.mega.co.nz
> Accept: */*
> Content-Length: 46
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 46 out of 46 bytes
< HTTP/1.1 200 OK
< Content-Type: application/json
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: Content-Type, MEGA-Chrome-Antileak
< Access-Control-Expose-Headers: Original-Content-Length
< Access-Control-Max-Age: 86400
< Original-Content-Length: 296
< Content-Length: 296
< Connection: keep-alive
< 
* Connection #0 to host g.api.mega.co.nz left intact
[{"s":4,"at":"gELEbMQ0rg3kEyC9sUtlORwYuQ_Kp19OMXm0Ju-u_enARPeJSc0DleBpdw_GjBIcFt8YHP_Jr_-r2Q7kywUt0w","msd":1,"tl":0,"g":"https://gfs270n062.userstorage.mega.co.nz/dl/_MNd6LXuuwPdJgIu2rQoEGaEeQBxvOiof03QMtKqbzrlny9BYGFfn9iaqMK2ubLMWbrNhFz11YEu1_Wdm7MAXXaKyu3__FA11XeCLrhQeh3LyIDdzN0EJIsOnrSbNw"}]

Tools

  • libopenssl
  • libsodium

Help

OpenSSL

  • openssl_cipher_iv_length
  • openssl_decrypt
  • aes128_cbc_decrypt

Sodium

  • SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_HEADERBYTES
  • sodium_crypto_secretbox_open
  • sodium_crypto_secretstream_xchacha20poly1305_init_pull

Max Base

My nickname is Max, Programming language developer, Full-stack programmer. I love computer scientists, researchers, and compilers. (Max Base)

Asrez Team

A team includes some programmer, developer, designer, researcher(s) especially Max Base.

Asrez Team

nginx-proxy-without-sni-conf

Nginx反向代理配置文件(不发送TLS SNI头),支持直连IP联通但是域名无法访问的情况。

局限性:不支持基于SNI分配证书的CDN,例如:Akamai、CloudFlare,不传输SNI无法获得证书从而无法通过IP直接连接(单IP多域名)。

部署

  1. git clone https://github.com/LittleJake/nginx-proxy-without-sni-conf/,拷贝conf.dca至Nginx配置文件目录;
  2. 签发自签名证书,进入ca目录依次执行sudo bash gen_ca_cert_key.shsudo bash bash gen_cert.sh,随便输入相关信息。
  3. 导入FakeCA.crt到计算机/手机内;
  4. 直接访问域名即可打开。

ps:后期添加域名后,执行sudo bash bash gen_cert.sh即可更新证书对应域名。

支持站点

SFW

站点 域名
Pixiv i.pximg.net
pixiv.net
ssl.pixiv.net
accounts.pixiv.net
touch.pixiv.net
oauth.secure.pixiv.net
www.pixiv.net
sketch.pixiv.net
app-api.pixiv.net
imgaz.pixiv.net
comic.pixiv.net
novel.pixiv.net
source.pixiv.net
i1.pixiv.net
i2.pixiv.net
i3.pixiv.net
i4.pixiv.net
dic.pixiv.net
en-dic.pixiv.net
sensei.pixiv.net
fanbox.pixiv.net
payment.pixiv.net
factory.pixiv.net
*.pixivsketch.net
*.pximg.net
imp.pixiv.net
Mega mega.nz
g.api.mega.co.nz
*.mega.nz
Wikipedia *.wikipedia.org
*.m.wikipedia.org
wikimedia.org
upload.wikimedia.org
Steam *.steamcommunity.com
steamcommunity.com
*.steampowered.com
steampowered.com
Archive of Our Own *.archiveofourown.org
archiveofourown.org

NSFW

站点 域名
Nyaa nyaa.si
www.nyaa.si
sukebei.nyaa.si
E-Hentai forums.e-hentai.org
ExHentai exhentai.org
*.exhentai.org

测试图

image

image

感谢

配置文件思路参考:mashirozx/Pixiv-Nginx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment