Last active 1 day ago

Revision a7dba81c707aff9c50e31cab39dc1b0e01d6ec17

send.sh Raw
1#!/bin/bash
2
3# --- 1. Configuration (Critical!) ---
4
5# These values are observed from your browser. They will likely expire!
6# When the script fails, you may need to re-capture these two values from your browser.
7FINGERPRINT="ZSbU9jU2AZWgnNagZ61vVua0RCZr46DT5eSwn8uHKsc8QFEFBhTVYPI7a1LWcrDAwOm%2F4AGv7rmTw%2F4xVTQqgA%3D%3D"
8RANDOM_STRING="SDQwjPd54R84tGaackbWmYNme4tmsD75"
9
10# Your User-Agent
11USER_AGENT="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"
12
13# !! Fill in the Referer and Origin from your "Copy as cURL"
14# !! These two headers are crucial for preventing 403 Forbidden errors
15REFERER_HEADER="https://hitools.hikvision.com/en/some-page-you-were-on"
16ORIGIN_HEADER="https://hitools.hikvision.com"
17# Check if 'X-Requested-With: XMLHttpRequest' is also in your 'Copy as cURL'
18X_REQ_WITH_HEADER="XMLHttpRequest"
19
20
21# --- 2. Preparation ---
22
23# Create a secure temporary file to store cookies
24COOKIE_JAR=$(mktemp)
25
26# Ensure the cookie file is deleted on script exit
27trap "rm -f $COOKIE_JAR" EXIT
28
29# Your API URLs
30GET_SESSION_URL="https://hitools.hikvision.com/TSAPI/User?fingerprint=${FINGERPRINT}&r=${RANDOM_STRING}&platform=indepLink&area=Global"
31POST_PRODUCT_URL="https://hitools.hikvision.com/en/TSAPI/ESServe/v2/products"
32
33# Your JSON data
34JSON_PAYLOAD='{
35 "bool": {
36 "or": {
37 "term": [
38 {
39 "key": "productBaseInfo.productSapId.keyword",
40 "value": "311326558"
41 }
42 ]
43 }
44 },
45 "productBracket": true
46}'
47
48
49# --- 3. Step 1: Get Session ---
50
51echo "Getting session..."
52# -s: Silent mode
53# -L: Follow redirects
54# -c: (cookie jar) Write cookies to the $COOKIE_JAR file
55# We also need to add UA and Referer to this GET request to simulate a browser
56curl -s -L \
57 -A "$USER_AGENT" \
58 -H "Referer: $REFERER_HEADER" \
59 -H "Origin: $ORIGIN_HEADER" \
60 -H "X-Requested-With: $X_REQ_WITH_HEADER" \
61 -c "$COOKIE_JAR" \
62 "$GET_SESSION_URL"
63
64# Check if the cookie file is empty
65if [ ! -s "$COOKIE_JAR" ]; then
66 echo "Failed to get session! Cookie file is empty."
67 exit 1
68fi
69
70echo "Session and Cookies saved to: $COOKIE_JAR"
71# You can inspect the cookies by uncommenting the next line
72# cat $COOKIE_JAR
73
74
75# --- 4. Step 2: POST Data Using the Session ---
76
77echo "POSTing data..."
78# -b: (cookie) Read cookies from the $COOKIE_JAR file
79curl -X POST \
80 -b "$COOKIE_JAR" \
81 -A "$USER_AGENT" \
82 -H "Content-Type: application/json" \
83 -H "Referer: $REFERER_HEADER" \
84 -H "Origin: $ORIGIN_HEADER" \
85 -H "X-Requested-With: $X_REQ_WITH_HEADER" \
86 -d "$JSON_PAYLOAD" \
87 "$POST_PRODUCT_URL"
88
89echo
90echo "Script execution finished."