Tuesday, January 30, 2018

decryption of openssl packets with static certificates

Leave a Comment

I am working on a ethical hacking project to monitor all the encrypted packets through openssl. I do have both the public and private keys (cert files). My application code snippet for regular packet decryption is as follows:

 SSL_library_init();  ctx = InitCTX();  server = OpenConnection(hostname, atoi(portnum));  ssl = SSL_new(ctx);      /* create new SSL connection state */  SSL_set_fd(ssl, server);    /* attach the socket descriptor */  ShowCerts(ssl);        /* get any certs */  SSL_write(ssl,acClientRequest, strlen(acClientRequest));   /* encrypt & send message */  bytes = SSL_read(ssl, buf, sizeof(buf)); /* get reply & decrypt */  SSL_free(ssl);        /* release connection state */ 

SSL_read basically gets the certificate at the time of handshaking and utilizes it for decrypting the data. Is there any way to provide the same certificate offline for decryption of data.

Any help/pointers would be highly appreciable.

0 Answers

Read More

Python: Read data from Highcharts after setExtreme

Leave a Comment

I'm trying to get the data from a Highcharts chart using Selenium. The issue I have with this is that the setExtremes function does not work with .options.data. How can I read data after using setExtremes using purely Python-based methods?

My code:

capabilities = webdriver.DesiredCapabilities().FIREFOX capabilities["marionette"] = True driver = webdriver.Firefox(capabilities=capabilities, executable_path=gecko_binary_path) driver.get(website) time.sleep(5)  temp = driver.execute_script('return window.Highcharts.charts[0].series[0]'                              '.xAxis[0].setExtremes(Date.UTC(2017, 0, 7), Date.UTC(2017, 0, 8))'                              '.options.data'                             )  data = [item for item in temp] print(data) 

1 Answers

Answers 1

The problem is setExtremes(min, max) method returns undefined, so you can not chain options. Solution is to wrap this method and pass on context, for example:

(function(H) {   H.wrap(H.Axis.prototype, 'setExtremes', function (proceed) {     proceed.apply(this, Array.prototype.slice.call(arguments, 1);     return this; // <-- context for chaining   }); })(Highcharts); 

Now we can use:

return window.Highcharts.charts[0].xAxis[0].setExtremes(min, max).series[0].options.data; 

Note: The snippet can be placed in a separate file and used like any other Highcharts plugin (simply load after Highcharts library).

Important

Axis object has references only to series that are bound to this axis. If you want to access any series on the chart use:

return window.Highcharts.charts[0].xAxis[0].setExtremes(min, max).chart.series[0].options.data; 
Read More

Monday, January 29, 2018

How to handle hardware back button in PWA developed using Ionic3

Leave a Comment

I have developed a PWA (Tab based) using Ionic 3. It is working fine until hardware back button or browser's back button is pressed in android browser. If it is running from home screen, pressing hardware back will close app. If app is running in chrome in android (only tested in chrome), hardware back or browser's back will reload PWA's first page, not previously visited page. How to handle these events in Ionic 3 PWA?

I am using lazy load for all pages.

What I tried so far:

  1. As per jgw96's comment here, I thought IonicPage will handle navigation itself. But it is not working.

  2. Used platform.registerBackButtonAction, but it's not for PWA.

  3. As per Webruster's suggestion below in Answers, tried code in app.component.ts. But no change.

Posting code:

    import { Component, ViewChild } from '@angular/core';     import { Nav, Platform, AlertController, Alert, Events, App, IonicApp, MenuController } from 'ionic-angular';      @Component({       templateUrl: 'app.html'     })     export class MyApp {       @ViewChild(Nav) nav: Nav;       rootPage:any = 'TabsPage';       constructor(public platform: Platform,         public alertCtrl: AlertController, public events: Events,           public menu: MenuController,           private _app: App,           private _ionicApp: IonicApp) {          platform.ready().then(() => {           this.configureBkBtnprocess ();         });       }        configureBkBtnprocess() {         if (window.location.protocol !== "file:") {           window.onpopstate = (evt) => {             if (this.menu.isOpen()) {               this.menu.close ();               return;             }     let activePortal = this._ionicApp._loadingPortal.getActive() ||       this._ionicApp._modalPortal.getActive() ||       this._ionicApp._toastPortal.getActive() ||       this._ionicApp._overlayPortal.getActive();      if (activePortal) {       activePortal.dismiss();       return;     }      if (this._app.getRootNav().canGoBack())       this._app.getRootNav().pop();           };            this._app.viewDidEnter.subscribe((app) => {             history.pushState (null, null, "");             });         }       }     } 

1 Answers

Answers 1

you have mentioned that you are working with the hardware back button on app and in browser so you didn't mention clearly what need to be done at what stage so i came up with the generalized solution which can be useful in most of the cases

app.component.ts

platform.ready().then(() => {        // your other plugins code...       this.configureBkBtnprocess ();      }); 

configureBkBtnprocess

private configureBkBtnprocess () {      // If you are on chrome (browser)     if (window.location.protocol !== "file:") {        // Register browser back button action and you can perform       // your own actions like as follows       window.onpopstate = (evt) => {          // Close menu if open         if (this._menu.isOpen()) {           this._menu.close ();           return;         }          // Close any active modals or overlays         let activePortal = this._ionicApp._loadingPortal.getActive() ||           this._ionicApp._modalPortal.getActive() ||           this._ionicApp._toastPortal.getActive() ||           this._ionicApp._overlayPortal.getActive();          if (activePortal) {           activePortal.dismiss();           return;         }          // Navigate back         if (this._app.getRootNav().canGoBack())          this._app.getRootNav().pop();        }       else{         // you are in the app       };    // Fake browser history on each view enter   this._app.viewDidEnter.subscribe((app) => {     history.pushState (null, null, "");   }); 
Read More

LDap GSSContext null srcName with spring security

Leave a Comment

We try to make Windows authentication using spring security.

When we saw that we cannot authenticate our domain user with our keytab file created for our local pc, we checked our service user and see that it's password is valid. Then we checked whether we can reach from local to AD-domain. No request reached from our local as we controlled with network monitoring tool on AD-domain server machine. We also checked that outgoing traffic from our client with the command below;

netstat -oan 1 | find /I "[IP_ADDRESS_OF_AD_DOMAIN]" 

We could reach to that IP from our local, tested with telnet.

Our application.properties is like below;

app.ad-domain= example.com app.ad-server= ldap://adds.example.com.tr/ app.service-principal= HTTP/local_pc.example.com.tr@EXAMPLE.COM.TR app.keytab-location= local_pc.keytab app.ldap-search-base= OU=All Users,DC=example,DC=com app.ldap-search-filter= "(| (userPrincipalName={0}) (sAMAccountName={0}))" 

As a result we cannot get srcName of GSSContext. This gssName variable equals to null. Related SunJaasKerberosTicketValidator code block is as below;

@Override public KerberosTicketValidation run() throws Exception {     byte[] responseToken = new byte[0];     GSSName gssName = null;     GSSContext context = GSSManager.getInstance().createContext((GSSCredential) null);     boolean first = true;     while (!context.isEstablished()) {         if (first) {             kerberosTicket = tweakJdkRegression(kerberosTicket);         }         responseToken = context.acceptSecContext(kerberosTicket, 0, kerberosTicket.length);         gssName = context.getSrcName();         if (gssName == null) {             throw new BadCredentialsException("GSSContext name of the context initiator is null");         }         first = false;     }     if (!holdOnToGSSContext) {         context.dispose();     }     return new KerberosTicketValidation(gssName.toString(), servicePrincipal, responseToken, context); } 

As we searched this GSSContext with null SrcName error, in general suggested solutions are related to keytab file . But in our problem, we cannot even reach AD server as we mentioned in the beginning.

related link: GSSContext with null SrcName

Is there any other suggestion?

Thanks...

0 Answers

Read More

Javascript and callbacks and defered. How can I run a function after a google gmail API request completes?

Leave a Comment

I have built up a javascript file that starts with:

var myApp = function () {  var CLIENT_ID = 'xxxxxxx'; var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest"]; var SCOPES = 'https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/analytics.readonly https://www.googleapis.com/auth/drive.readonly'; var authorizeButton = document.getElementById('authorize-button');  return { 

The functions are declared like:

    getSent: function(callback) {     var request = gapi.client.gmail.users.messages.list({       'userId': 'me',       'labelIds': 'SENT',       'maxResults': 10     });      request.execute(function(response) {       $.each(response.messages, function() {         var messageRequest = gapi.client.gmail.users.messages.get({           'userId': 'me',           'id': this.id         });           messageRequest.execute(myApp.appendMessageRow);       });     });   }, 

And then run through a single function that calls others:

myApp.init(); 

How can I defer a function to be run after my google request function getsent() has been fully completed. I have tried using callbacks to another function and it runs but it runs while the getsent() is still being executed. Can I use the jQuery method defered to run the callback when done?

I have tried: myApp.getSent(myApp.gMailSyncComplete()); // Runs early

and I tried: myApp.getSent().done(myApp.gMailSyncComplete()); // no jQuery done defined

4 Answers

Answers 1

Some important errors in your code:

  • You are creating a function getSent that accepts a callback, but you are not calling the callback at all so it won't get executed ever. You should execute the callback when everything else is done.
  • You are not waiting for all message requests to be completed. You can use a library like async which has the method map to be able to execute all requests in parallel and wait for all of them to be completed before calling the callback.

With these two things in mind, and using async, this would be an example of the resulting code:

getSent: function (callback) {   var request = gapi.client.gmail.users.messages.list({     'userId': 'me',     'labelIds': 'SENT',     'maxResults': 10   })    request.execute(function (response) {     async.map(response.messages, function (msg, cb) {         var messageRequest = gapi.client.gmail.users.messages.get({           'userId': 'me',           'id': msg.id         })          messageRequest.execute(function (result) {             myApp.appendMessageRow(result)             cb()         })     }, function (err) {       if (err) throw err       callback()     })   }) } 
  • Lastly, when invoking this function, keep in mind that the callback parameter must be a function.

To make things clear, let's translate the code you wrote, myApp.getSent(myApp.gMailSyncComplete()), into an equivalent structure:

var callback = myApp.gMailSyncComplete() myApp.getSent(callback) 

When you do this, you are not passing the function but the result of the function, because you are executing it. That's why it gets executed immediately. The correct way to do this would be the following:

var callback = myApp.gMailSyncComplete myApp.getSent(callback) 

Or, in your one-liner example, myApp.getSent(myApp.gMailSyncComplete)

Answers 2

you can use javascript promise.

    function testPromise() {       let p1 = new Promise(         // The resolver function is called with the ability to resolve or         // reject the promise        (resolve, reject) => {             /*your async function*/         }     );   // defined what to do when the promise is resolved with the then() call,     // and what to do when the promise is rejected with the catch() call     p1.then(         // Log the fulfillment value         function(val) {             log.insertAdjacentHTML('beforeend', val +                 ') Promise fulfilled (<small>Async code terminated</small>)<br/>');         })     .catch(         // Log the rejection reason        (reason) => {             console.log('Handle rejected promise ('+reason+') here.');         }); } 

Answers 3

You could use jQuery promise(), check the example below.

getSent: function() { var request = gapi.client.gmail.users.messages.list({   'userId': 'me',   'labelIds': 'SENT',   'maxResults': 10 });  request.execute(function(response) {   $.each(response.messages, function() {     var messageRequest = gapi.client.gmail.users.messages.get({       'userId': 'me',       'id': this.id     });       messageRequest.execute(myApp.appendMessageRow);   }); }); }, ... $.when( myApp.getSent() ).done(function() {     // do whatever you want in here as callback }); 

Answers 4

Inside of your getSent function create a jQuery Deferred object and return a promise. Then after request.execute has finished you can call resolve/reject. I created a small snippet to show example. Maybe you can modify to fit your needs

$(document).ready(function () {      var i =0;        function getText() {          var deferred = $.Deferred();          setTimeout(function () {              i++;              deferred.resolve("text " + i);          }, 3000);          return deferred.promise();      }      getText().then(function (value) {          console.log(value);      }).then(function () {          getText().then(function (value2) {              console.log(value2);          });      });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Read More

multiprocessing.Pipe is even slower than multiprocessing.Queue?

Leave a Comment

I tried to benchmark the speed up of Pipe over Queue from the multiprocessing package. T thought Pipe would be faster as Queue uses Pipe internally.

Strangely, Pipe is slower than Queue when sending large numpy array. What am I missing here?

Pipe:

import sys import time from multiprocessing import Process, Pipe import numpy as np  NUM = 1000   def worker(conn):     for task_nbr in range(NUM):         conn.send(np.random.rand(400, 400, 3))     sys.exit(1)   def main():     parent_conn, child_conn = Pipe(duplex=False)     Process(target=worker, args=(child_conn,)).start()     for num in range(NUM):         message = parent_conn.recv()   if __name__ == "__main__":     start_time = time.time()     main()     end_time = time.time()     duration = end_time - start_time     msg_per_sec = NUM / duration      print "Duration: %s" % duration     print "Messages Per Second: %s" % msg_per_sec  # Took 10.86s. 

Queue

import sys import time from multiprocessing import Process from multiprocessing import Queue import numpy as np  NUM = 1000  def worker(q):     for task_nbr in range(NUM):         q.put(np.random.rand(400, 400, 3))     sys.exit(1)  def main():     recv_q = Queue()     Process(target=worker, args=(recv_q,)).start()     for num in range(NUM):         message = recv_q.get()  if __name__ == "__main__":     start_time = time.time()     main()     end_time = time.time()     duration = end_time - start_time     msg_per_sec = NUM / duration      print "Duration: %s" % duration     print "Messages Per Second: %s" % msg_per_sec  # Took 6.86s. 

2 Answers

Answers 1

You can do an experiment and put the following into your Pipe code above..

def worker(conn):     for task_nbr in range(NUM):         data = np.random.rand(400, 400, 3)     sys.exit(1)  def main():     parent_conn, child_conn = Pipe(duplex=False)     p = Process(target=worker, args=(child_conn,))     p.start()     p.join() 

This gives you the time that it takes to create the data for your test. On my system this takes about 2.9 seconds.

Under the hood the queue object implements a buffer and a threaded send. The thread is still in the same process but by using it, the data creation doesn't have to wait for the system IO to complete. It effectively parallelizes the operations. Try your Pipe code modified with some simple threading implemented (disclaimer, code here is for test only and is not production ready)..

import sys import time import threading from multiprocessing import Process, Pipe, Lock import numpy as np import copy  NUM = 1000  def worker(conn):     _conn = conn     _buf = []     _wlock = Lock()     _sentinel = object() # signal that we're done     def thread_worker():         while 1:             if _buf:                 _wlock.acquire()                 obj = _buf.pop(0)                 if obj is _sentinel: return                 _conn.send(data)                 _wlock.release()     t = threading.Thread(target=thread_worker)     t.start()     for task_nbr in range(NUM):         data = np.random.rand(400, 400, 3)         data[0][0][0] = task_nbr    # just for integrity check         _wlock.acquire()         _buf.append(data)         _wlock.release()     _wlock.acquire()     _buf.append(_sentinel)     _wlock.release()     t.join()     sys.exit(1)  def main():     parent_conn, child_conn = Pipe(duplex=False)     Process(target=worker, args=(child_conn,)).start()     for num in range(NUM):         message = parent_conn.recv()         assert num == message[0][0][0], 'Data was corrupted'          if __name__ == "__main__":     start_time = time.time()     main()     end_time = time.time()     duration = end_time - start_time     msg_per_sec = NUM / duration      print "Duration: %s" % duration     print "Messages Per Second: %s" % msg_per_sec 

On my machine this takes 3.4 seconds to run which is almost exactly the same as your Queue code above.

From https://docs.python.org/2/library/threading.html

In Cython, due to due to the Global Interpreter Lock, only one thread can execute Python code at once... however, threading is still an appropriate model if you want to run multiple I/O-bound tasks simultaneously.

The queue and pipe differences are definitely an odd implementation detail until you dig into it a bit.

Answers 2

I assume by your print command you are using Python2. However the strange behavior cannot be replicated with Python3, where Pipe is actually faster than Queue.

import sys import time from multiprocessing import Process, Pipe, Queue import numpy as np  NUM = 20000   def worker_pipe(conn):     for task_nbr in range(NUM):         conn.send(np.random.rand(40, 40, 3))     sys.exit(1)   def main_pipe():     parent_conn, child_conn = Pipe(duplex=False)     Process(target=worker_pipe, args=(child_conn,)).start()     for num in range(NUM):         message = parent_conn.recv()   def pipe_test():     start_time = time.time()     main_pipe()     end_time = time.time()     duration = end_time - start_time     msg_per_sec = NUM / duration     print("Pipe")     print("Duration: " + str(duration))     print("Messages Per Second: " + str(msg_per_sec))  def worker_queue(q):     for task_nbr in range(NUM):         q.put(np.random.rand(40, 40, 3))     sys.exit(1)  def main_queue():     recv_q = Queue()     Process(target=worker_queue, args=(recv_q,)).start()     for num in range(NUM):         message = recv_q.get()  def queue_test():     start_time = time.time()     main_queue()     end_time = time.time()     duration = end_time - start_time     msg_per_sec = NUM / duration     print("Queue")     print("Duration: " + str(duration))     print("Messages Per Second: " + str(msg_per_sec))   if __name__ == "__main__":     for i in range(2):         queue_test()         pipe_test() 

Results in:

Queue Duration: 3.44321894646 Messages Per Second: 5808.51822408 Pipe Duration: 2.69065594673 Messages Per Second: 7433.13169575 Queue Duration: 3.45295906067 Messages Per Second: 5792.13354361 Pipe Duration: 2.78426194191 Messages Per Second: 7183.23218766   ------------------ (program exited with code: 0) Press return to continue 
Read More

Grouping ID-identified pages in Google Analytics

Leave a Comment

I've been tasked to generate more useful data out of our google analytics account.

We have URL paths that include the ID of a given object, say a product, workspace, or device. So routes could look like

/ide/products/8a8985cf-8a74-ee7a-a9a3-d1335a4a7ad6/workspaces/987dd13e-57a3-353b-2b42-db58c479d0ca/draft/devices/40000c2a69109dd8

/ide/products/531743df-3d77-ec6b-4014-d33925639743/workspaces/e0eb62fc-e7d2-56ec-56cf-79ae53714de3/draft

/ide/products/65bc6914-4ddd-1718-0d47-e91b0ff1dff1/workspaces/f7b526ad-7e5c-7f11-f4ad-bb53f8e583d7/draft

/ide/products/65bc6914-4ddd-1718-0d47-e91b0ff1dff1/workspaces/f7b526ad-7e5c-7f11-f4ad-bb53f8e583d7/deployments

Following the pattern /ide/products/{{product_id}}/workspaces/{{workspace_id}}/{{page}} , among other things.

In "Behavior Flow," I'm trying to show how users navigate from /ide to /ide/products to ide/products/{{any_product_id}}/workspaces to ide/products/{{any_product_id}}/workspaces/{{any_workspaces_id}}/draft but am unclear how to create groupings that ignore arbitrary IDs. I've tried "Content Groupings" but those seem to be more high-level than what I'm looking for, in that I must "select" one as a top-level filter in the behavior flow chart (as opposed to "automatic groupings").

How can I demonstrate user flow that is identical regardless of the actual ID of the object being "plugged into" a given page? How do I see charts in Google Analytics that treat

/ide/products/65bc6914-4ddd-1718-0d47-e91b0ff1dff1/workspaces/f7b526ad-7e5c-7f11-f4ad-bb53f8e583d7/draft

/ide/products/531743df-3d77-ec6b-4014-d33925639743/workspaces/e0eb62fc-e7d2-56ec-56cf-79ae53714de3/draft

as the same route?

EDIT: Another example: I'm looking at behavior > Page Timings, with Primary Dimension set to "Page." I'm seeing /ide/products/{{id_1}}/workspaces/{{workspace_1}}/draft and /ide/products/{{id_2}}/workspaces/{{workspace_2}}/draft as separate entities, when ideally they would be treated as a single entity, as page load time is affected by the application features on that page (which are universal regardless of the given ID).

1 Answers

Answers 1

You can totally get this done by using event tracking. Not sure how well your Javascript knowledge but here is what I've done for projects that I've worked on.

1. Implement event tracking

Use Javascript to send event based on page, user actions or whatever event. Read simple guide from Google https://developers.google.com/analytics/devguides/collection/gtagjs/events . In your case, you will need to have Javascript code in the four pages and send event according to the page users are loading. They look something like this:

IDE page

gtag('event', 'ide', {   'event_category': 'page_load',   'event_label': 'Google' }); 

Products page

gtag('event', 'products', {   'event_category': 'page_load',   'event_label': 'Google' }); 

Wordspaces page

gtag('event', 'products', {   'event_category': 'page_load',   'event_label': 'Google' }); 

Workspaces page

gtag('event', 'workspaces', {   'event_category': 'page_load',   'event_label': 'Google' }); 

2. Viewing event flow

After implementing and making sure that Google receiving events. Open Google Analytics dashboard > Behaviors > Events > Event Flow

Enjoy the result!

Read More