up_imagebam.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
echo -e "\e]0;up_imagebam.sh\a"
file="$1"
filename="$(basename "$file")"
cookies=$(mktemp /tmp/_imagebam_session.XXXXXXX)
TorPort=${TorPort:-9050}
cpass=$RANDOM$RANDOM:$RANDOM

torcurl() {
  curl -x "socks5h://${cpass}@127.0.0.1:${TorPort}" -Ls \
  -A "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0" \
  -H "Referer: https://www.imagebam.com/" \
  -H "Origin: https://www.imagebam.com" \
  -H 'X-Requested-With: XMLHttpRequest' \
  --connect-timeout 20 --max-time 35 \
  "$@"
}

init=$(torcurl -c "$cookies" -i -X GET \
  -H "Content-Type: application/x-www-form-urlencoded" \
  "https://www.imagebam.com/")

csrf_token=$(grep -Po '(?<="csrf-token" content=").*(?=">)' <<< "${init}" )

session=$(torcurl -b "$cookies" -c "$cookies" -X POST \
  -H 'Accept: application/json, text/javascript, */*; q=0.01' \
  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H "X-CSRF-TOKEN: ${csrf_token}" \
  -d 'thumbnail_size=1&content_type=nsfw&comments_enabled=false' \
  "https://www.imagebam.com/upload/session")

data=$(jq -r '.data' <<< "$session")

post=$(torcurl -b "$cookies" -X POST \
  -H 'Accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -F "files[0]=@${file}" \
  -F "data=${data}" \
  -F "_token=${csrf_token}" \
  "https://www.imagebam.com/upload")

# url to 'upload complete' page
success=$(jq -r '.success'  <<< "$post" | sed 's/\\\\//')

# visit success, find url to viewer page
viewer_url=$(torcurl -X GET "$success" |
  grep -Po '(?=https://www.imagebam.com/view/).*(?= ">)' -m1)

# visit viewer page (+set cookie value to bypass javascript block)
# find url to /actual/ image
direct_url=$(torcurl -X GET "$viewer_url" -b nsfw_inter="1" |
  grep -Po '(?=https://images4.i).*(?=" alt=")')

# "bam"!
printf "\\n"
echo "Direct URL: ${direct_url}"