开发者

CCTV webserver javascript

开发者 https://www.devze.com 2023-03-07 07:10 出处:网络
Bit of a strange one here, i have a CCTV system开发者_JAVA技巧 and contacted the manufacturers to asked if there was an API. The answer was no.

Bit of a strange one here, i have a CCTV system开发者_JAVA技巧 and contacted the manufacturers to asked if there was an API. The answer was no.

I've been trying to understand how i can take the live jpeg picture and use it in my own app (c#).

here is a link to the liveview page that displays the the live feeds; http://pastebin.com/jCp4jZRh

The line i'm interested in is;

img_buf[0].src = "ivop.get?action=live&piccnt=0&THREAD_ID=" + thd_id;

Now piccnt seems to be for stopping browsers caching the data, so this number keeps changing and thd_id seems to be the channel number. When trying to access this i get the following message;

Authentication Error:Access Denied, authentication error

Even if i log in first, then try the above url with my own contect i still retrieve the access denied message.

Heres the source to the login page; http://pastebin.com/q7nLJ4tk heres the source to the md5.js file; http://pastebin.com/du1ggaQB

I'm just a little stuck on how to auth then display the feed, does anyone have any pointers?

thanks


I answered a similar question awhile back, and the solution ended up being that you had to set the referrer.

In any case, to find your solution, download a copy of Fiddler.

Once running, hit your camera page, and you will see several requests. When you find one of the requests for ivop.get, drag it into the request builder and execute it a second time.

If after executing it a second time it still works (check using the inspectors), then start changing the headers, removing bits one by one until you find the key element. I suspect there will either be a cookie, or referrer that is required.

Once you have figured out those elements, it should be easy to make the appropriate request in your application.

If you can post a live URL, I can help you with this.


Best guess given the limited info available: they're checking the referrer. You can check the details of the requests using Fiddler (you can even replay the request with a slightly different referrer, confirm if that's what's happening, etc). If this is it, you can set the referrer in HTTPWebRequest: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.referer.aspx


There are many possibilities, and without having access to the source code of the CCTV server, it's hard to say which one it might be.

I'd suggest popping open an HTTP Header sniffing utility (such as https://addons.mozilla.org/en-US/firefox/addon/live-http-headers/ for firefox) and watch the headers for the successful IMG request. Then replay that request using netcat or curl. Once you've got that working, try removing HTTP headers one at a time (you're probably sending some kind of session ID, HTTP Referrer, etc - these may all be important to the CCTV server)

In any case, it's almost certainly going to be important that you at least authenticate with mlogin.get and pass along the resulting session ID in subsequent requests.


Whilst this may be old - i had the same problem. The DVR requires an authenticated login with a key sent in the url during the first redirect to the login page, and the password in hex_hmac_md5. I have a python function to login and retrieve two channel images and then logout below:

def getcamimg():
    baseurl = 'http://<IPADDRESS>/'
    content = str(getUrl(baseurl))
    x = re.search("key=(\w+)", content)
    keystr = x.group(1)
    key = bytes(keystr,'utf-8')
    password = bytes(<YOURPASS>,'utf-8')
    hmacobj = hmac.new(key,password)
    hmacpass = hmacobj.hexdigest()
    #-----------------------------------------------------
    loginurl = baseurl + 'mlogin.get?account=<USERNAME>&passwd='+ str(hmacpass) + '&key=' + keystr + '&Submit=Login'
    lcontent = str(getUrl(loginurl))
    if("another administrator" in lcontent):
        print("another admin online")
        exit()
    y = re.search('href="([\w\d\.\?=&_-]+)"',lcontent) 
    finalurl = baseurl + y.group(1)
    z = re.search('id=(\w+)',lcontent)
    thid = z.group(1)
    #-----------------------------------------------------
    imgurl = baseurl + "ivop.get?action=live&piccnt=1&THREAD_ID=" + thid
    imgcontent = getUrl(imgurl)
    ctime = datetime.datetime.today().strftime("%Y%m%d%H%M%S")
    with open("chan1_"+ctime+".jpg", "wb") as file0:
        file0.write(imgcontent)
    #-----------------------------------------------------
    chanset = "showch.set?channel=3&THREAD_ID=" + thid
    getUrl(baseurl + chanset)
    #-----------------------------------------------------
    icontent1 = getUrl(imgurl)
    with open("chan3_"+ctime+".jpg", "wb") as file1:
        file1.write(icontent1)
    #-----------------------------------------------------
    logout = "Forcekick.set?ITSELF=1&Logout=Logout&THREAD_ID=" + thid
    getUrl(baseurl + logout)
    #-----------------------------------------------------
def getUrl(url):
    try:
        response = requests.get(url)
        response.raise_for_status()
    except HTTPError as http_err:
        print('HTTP error occurred: '+ str(http_err))
    except Exception as err:
        print('Other error occurred:' + str(err)) 
    else:
        return response.content
0

精彩评论

暂无评论...
验证码 换一张
取 消