<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="https://cyberloginit.com//feed.xml" rel="self" type="application/atom+xml" /><link href="https://cyberloginit.com//" rel="alternate" type="text/html" /><updated>2023-03-25T02:05:23+00:00</updated><id>https://cyberloginit.com//feed.xml</id><title type="html">Cyberloginit</title><subtitle>Cyber Log in IT.</subtitle><entry><title type="html">Utelnetd Interface Parameter Stack Buffer Overflow</title><link href="https://cyberloginit.com//2020/07/26/utelnetd-interface-parameter-stack-buffer-overflow.html" rel="alternate" type="text/html" title="Utelnetd Interface Parameter Stack Buffer Overflow" /><published>2020-07-26T00:00:00+00:00</published><updated>2020-07-26T00:00:00+00:00</updated><id>https://cyberloginit.com//2020/07/26/utelnetd-interface-parameter-stack-buffer-overflow</id><content type="html" xml:base="https://cyberloginit.com//2020/07/26/utelnetd-interface-parameter-stack-buffer-overflow.html">&lt;h1 id=&quot;utelnetd-interface-parameter-stack-buffer-overflow&quot;&gt;Utelnetd Interface Parameter Stack Buffer Overflow&lt;/h1&gt;

&lt;h2 id=&quot;utelnetd&quot;&gt;Utelnetd&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;utelnetd is a small and efficient stand alone Telnet server daemon.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The source code can be downloaded from &lt;a href=&quot;https://public.pengutronix.de/software/utelnetd/&quot;&gt;Pengutronix&lt;/a&gt;, and the latest version is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.1.11&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;2008-08-11	Marc Kleine-Budde &lt;a href=&quot;mailto:mkl@pengutronix.de&quot;&gt;mkl@pengutronix.de&lt;/a&gt;&lt;/p&gt;

  &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;	- Revision 0.1.11 released
	- added CFLAGS to linking stage
	 (thanks to Remy Bohmer &amp;lt;linux@bohmer.net&amp;gt;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;There is also a SourceForge &lt;a href=&quot;https://sourceforge.net/projects/utelnetd/&quot;&gt;project&lt;/a&gt;, but the latest version is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.1.9&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;At present, the only major Linux distro still has Utelnetd in its packages repository is &lt;a href=&quot;https://packages.gentoo.org/packages/net-misc/utelnetd&quot;&gt;Gentoo&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;buffer-overflow&quot;&gt;Buffer Overflow&lt;/h2&gt;

&lt;p&gt;The stack buffer overflow vulnerability affects Utelnetd version from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.1.7&lt;/code&gt; to the latest &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.1.11&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;2003-08-06	Robert Schwebel &lt;a href=&quot;mailto:r.schwebel@pengutronix.de&quot;&gt;r.schwebel@pengutronix.de&lt;/a&gt;&lt;/p&gt;

  &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;	- Revision 0.1.7 released
	- changed Makefile and utelnetd.c to work with BSD
	  (thanks to Sepherosa Ziehau &amp;lt;sepherosa@myrealbox.com&amp;gt;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;When the compatibility with BSD was introduced in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Revision 0.1.7&lt;/code&gt;,&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;if (interface_name) {
    strncpy(interface.ifr_ifrn.ifrn_name, interface_name, IFNAMSIZ);
    (void)setsockopt(master_fd, SOL_SOCKET,
            SO_BINDTODEVICE, &amp;amp;interface, sizeof(interface));
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;was changed to&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;if (interface_name) {

    strcpy(interface.ifr_name, interface_name);

    /* use ioctl() here as BSD does not have setsockopt() */
    if (ioctl(master_fd, SIOCGIFADDR, &amp;amp;interface) &amp;lt; 0) {
        printf(&quot;Please check the NIC you specified with -i option\n&quot;);
        perror(&quot;ioctl SIOCGFADDR&quot;);
        return 1;
    }

    sa.sin_addr = ((struct sockaddr_in *)(&amp;amp;interface.ifr_addr))-&amp;gt;sin_addr;
} else 
    sa.sin_addr.s_addr = htonl(INADDR_ANY);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Especially, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;strncpy(interface.ifr_ifrn.ifrn_name, interface_name, IFNAMSIZ);&lt;/code&gt; was changed to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;strcpy(interface.ifr_name, interface_name);&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The user-controlled &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;interface&lt;/code&gt; parameter(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;interface_name&lt;/code&gt; local string variable) is copied to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;interface.ifr_name&lt;/code&gt; element from the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;struct ifreq interface&lt;/code&gt; local variable without having its length checked.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;interface.ifr_name&lt;/code&gt; has a fix length of &lt;strong&gt;16&lt;/strong&gt; bytes on Linux systems like Ubuntu 18.04 64 bit.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;valgrind --leak-check=full ./utelnetd -p 8000 -l /bin/sh -i &quot;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/images/utelnetd_interface_parameter_stack_buffer_overflow.png&quot; alt=&quot;Stack Buffer Overflow PoC&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;exploit&quot;&gt;Exploit&lt;/h2&gt;

&lt;p&gt;On a multi-user system with root and non-root users, if the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;utelnetd&lt;/code&gt; executable file has the &lt;strong&gt;setuid&lt;/strong&gt; attribute, malicious user could overflow the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;interface.ifr_name&lt;/code&gt; buffer and overwrite the EIP/RIP register to achieve privilege escalation and effectively take control of the whole system as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;root&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;reference&quot;&gt;Reference&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://public.pengutronix.de/software/utelnetd/&quot;&gt;https://public.pengutronix.de/software/utelnetd/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://packages.gentoo.org/packages/net-misc/utelnetd&quot;&gt;https://packages.gentoo.org/packages/net-misc/utelnetd&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://sourceforge.net/projects/utelnetd/&quot;&gt;https://sourceforge.net/projects/utelnetd/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">Utelnetd Interface Parameter Stack Buffer Overflow</summary></entry><entry><title type="html">D-Link SharePort Web Access Authentication Bypass</title><link href="https://cyberloginit.com//2019/09/10/dlink-shareport-web-access-authentication-bypass.html" rel="alternate" type="text/html" title="D-Link SharePort Web Access Authentication Bypass" /><published>2019-09-10T00:00:00+00:00</published><updated>2019-09-10T00:00:00+00:00</updated><id>https://cyberloginit.com//2019/09/10/dlink-shareport-web-access-authentication-bypass</id><content type="html" xml:base="https://cyberloginit.com//2019/09/10/dlink-shareport-web-access-authentication-bypass.html">&lt;h1 id=&quot;d-link-shareport-web-access-authentication-bypass&quot;&gt;D-Link SharePort Web Access Authentication Bypass&lt;/h1&gt;

&lt;h2 id=&quot;vulnerability-description&quot;&gt;Vulnerability Description&lt;/h2&gt;

&lt;p&gt;SharePort Web Access is a feature available to most D-Link wireless home routers with a USB port.&lt;/p&gt;

&lt;p&gt;It is enabled by default.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/default_config_file.png&quot; alt=&quot;default_config_file&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Tutorial  from its &lt;a href=&quot;https://eu.dlink.com/uk/en/support/faq/routers/mydlink-routers/dir-880l/how-do-i-configure-shareport-web-access-on-my-router&quot;&gt;website&lt;/a&gt; shows that just insert your USB Flash Drive into your router, then you will be able to access it from the Internet by visit a URL like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://[ip]:8181&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Theoretically you have to be authorized by entering your router’s administrator username and password.&lt;/p&gt;

&lt;p&gt;However, D-Link screws it up pretty badly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First&lt;/strong&gt;: If you have not changed them from the defaults, the username should be Admin, and the password field should be left &lt;strong&gt;blank&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second&lt;/strong&gt;: The authentication can be bypassed directly. Just visit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;folder_view.php&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;category_view.php&lt;/code&gt; or any valid page in this path and authentication is not required, including even &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;logininfo.xml&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In some cases, visit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://[ip]:[port]/webaccess/folder_view.php&lt;/code&gt; instead &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://[ip]:[port]/folder_view.php&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/web_access_directory.png&quot; alt=&quot;web_access_directory&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;vulnerability-scope&quot;&gt;Vulnerability Scope&lt;/h2&gt;

&lt;p&gt;At least these wireless router models below are affected, each with its latest firmware installed.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Model&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Revision&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Firmware&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Note&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;DIR-868L&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;REVB&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;2.03&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Latest&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;DIR-885L&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;REVA&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1.20&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Latest&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;DIR-895L&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;REVA&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1.21&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Latest&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;vulnerability-analysis&quot;&gt;Vulnerability Analysis&lt;/h2&gt;

&lt;p&gt;So, how the authentication fails ？&lt;/p&gt;

&lt;p&gt;Take &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://[ip]:[port]/folder_view.php&lt;/code&gt; for example.&lt;/p&gt;

&lt;h3 id=&quot;authentication-functions&quot;&gt;Authentication Functions&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;folder_view.php&lt;/code&gt; is actually a HTML with JavaScript, nothing PHP here.&lt;/p&gt;

&lt;p&gt;On line 719&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;body onLoad=&quot;load_value();get_login_info()&quot;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get_login_info()&lt;/code&gt; is supposed to do the authentication .&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/call_flow.png&quot; alt=&quot;call_flow&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get_login_info()&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;get_login_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;xml_request&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;XMLRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;get_login_info_result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;para&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;request=get_login_info&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;nx&quot;&gt;xml_request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;exec_webfile_cgi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;para&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;XMLRequest()&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/**
 * XMLRequest( ) - Constructor for building XMLRequest Object 
 
 *	Parameter(s) :
 * 	onReqComp : the function that you want to perform after receive response from the web server
 *
 * Variable(s) :
 * 	http_req   :  user custom function for performing post response.
 * 	onReqComp  :  user custom function for performing post response.
 *
 **/&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;XMLRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onReqComp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;http_req&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;create_http_request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;	
	&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onReqComp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;onReqComp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;	
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;cm&quot;&gt;/**
 * XMLRequest.prototype - Prototype of XMLRequest Object 
 *
 * Data members:
 * 	READY_STATE_***:  ready state constants
 *
 * Methods:
 * 	loading_xml()		:  get remote xml document
 * 	exec_cgi()			:  requesting server performing CGI command
 *  	get_login_level() :  get user's login level
 * 	onReadyState()		:  callback function while readystate changing
 **/&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;XMLRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;prototype&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;READY_STATE_UNINITIALIZED&lt;/span&gt; 	&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;READY_STATE_LOADING&lt;/span&gt; 			&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;READY_STATE_LOADED&lt;/span&gt; 			&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;READY_STATE_INTERACTIVE&lt;/span&gt; 	&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;READY_STATE_COMPLETE&lt;/span&gt; 		&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;


&lt;span class=&quot;na&quot;&gt;loading_xml&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;which_url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;	
	&lt;span class=&quot;c1&quot;&gt;//...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;exec_cgi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;para&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
	&lt;span class=&quot;c1&quot;&gt;//...			&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;exec_webfile_cgi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;para&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;req_url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;logininfo.xml?&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;para&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;obj&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		
	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;http_req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;	
		&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;http_req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onreadystatechange&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;obj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onReadyState&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;obj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)};&lt;/span&gt;				
		&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;http_req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;GET&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;req_url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;http_req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setRequestHeader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Content-length&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;para&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;	
		&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;http_req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setRequestHeader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Connection&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;http_req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;		
		
		&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;			
	
	&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;			
&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;exec_auth_cgi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;para&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
	&lt;span class=&quot;c1&quot;&gt;//...	&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;json_cgi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;para&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
	&lt;span class=&quot;c1&quot;&gt;//...		&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;get_login_level&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;	
	&lt;span class=&quot;c1&quot;&gt;//...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;

&lt;span class=&quot;na&quot;&gt;onReadyState&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
	&lt;span class=&quot;c1&quot;&gt;//...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get_login_info_result()&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;get_login_info_result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;http_req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
	&lt;span class=&quot;c1&quot;&gt;//...&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;my_xml&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;http_req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;responseXML&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;check_user_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;my_xml&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;redirect_page&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])){&lt;/span&gt;

		&lt;span class=&quot;nx&quot;&gt;storage_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;get_node_value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;my_xml&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;user_name&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
		&lt;span class=&quot;nx&quot;&gt;storage_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;tok&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;get_node_value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;my_xml&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;user_pwd&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;

		&lt;span class=&quot;nx&quot;&gt;load_webfile_settings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;check_user_info()&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/**
 *	check_user_info() : to check if the user has login yet
 *
 *	Parameter(s) :
 *		redirect_page : a XML's element object which contains a redirect page
 *
 * Return :	True or False
 * 	
 **/&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;check_user_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;redirect_page&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;which_page&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;redirect_page&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;	
		&lt;span class=&quot;nx&quot;&gt;which_page&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;redirect_page&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;firstChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;nodeValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;nx&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;href&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;html_obj&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;get_value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;which_page&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;				
		&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
	
	&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;how-it-failed&quot;&gt;How It Failed&lt;/h3&gt;

&lt;p&gt;When &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get_login_info()&lt;/code&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GET&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;http://[ip]:[port]/logininfo.xml?request=get_login_info
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We get&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;cp&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot;?&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;root&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;user_name&amp;gt;&lt;/span&gt;admin&lt;span class=&quot;nt&quot;&gt;&amp;lt;/user_name&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;user_pwd&amp;gt;&lt;/span&gt;t&lt;span class=&quot;nt&quot;&gt;&amp;lt;/user_pwd&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;nt&quot;&gt;&amp;lt;volid&amp;gt;&lt;/span&gt;1&lt;span class=&quot;nt&quot;&gt;&amp;lt;/volid&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/root&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get_login_info_result()&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;var my_xml = http_req.responseXML;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;my_xml&lt;/code&gt; is actually the XML content above.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;my_xml.getElementsByTagName(&quot;redirect_page&quot;)&lt;/code&gt; should return&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HTMLCollection []
length: 0
__proto__: HTMLCollection
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And if we should try to take its first element, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undefined&lt;/code&gt; is returned.&lt;/p&gt;

&lt;p&gt;In &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;get_login_info_result()&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-js highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;check_user_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;my_xml&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;redirect_page&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])){&lt;/span&gt;

	&lt;span class=&quot;nx&quot;&gt;storage_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;get_node_value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;my_xml&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;user_name&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;storage_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;put&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;tok&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;get_node_value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;my_xml&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;user_pwd&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;

	&lt;span class=&quot;nx&quot;&gt;load_webfile_settings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;check_user_info(my_xml.getElementsByTagName(&quot;redirect_page&quot;)[0])&lt;/code&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;True&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;load_webfile_settings()&lt;/code&gt; will be executed, which means user is authorized to visit this page &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;folder_view.php&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;However, in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;check_user_info()&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;function check_user_info(redirect_page){
	var which_page;
	
	if (redirect_page != null){	
		which_page = redirect_page.firstChild.nodeValue;
		location.href = html_obj.get_value(which_page);				
		return 0;
	}
	
	return 1;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If element &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;redirect_page = my_xml.getElementsByTagName(&quot;redirect_page&quot;)[0]&lt;/code&gt;  does not exist, &lt;strong&gt;1&lt;/strong&gt; is returned, and user is authorized to proceed !&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;p&gt;The authentication procedure for D-Link SharePort Web Access basically fails at every aspects.&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Frontend authentication is not very reliable;&lt;/li&gt;
  &lt;li&gt;Name your variable wisely, or you will most likely pay for it.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;reference&quot;&gt;Reference&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://eu.dlink.com/uk/en/support/faq/routers/mydlink-routers/dir-880l/how-do-i-configure-shareport-web-access-on-my-router&quot;&gt;https://eu.dlink.com/uk/en/support/faq/routers/mydlink-routers/dir-880l/how-do-i-configure-shareport-web-access-on-my-router&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">D-Link SharePort Web Access Authentication Bypass</summary></entry><entry><title type="html">使用Fiddler嗅探Android App网络流量并还原大象公会RESTful API</title><link href="https://cyberloginit.com//2018/05/21/sniff-android-app-traffic-with-fiddler-and-uncover-restful-api-of-elephant-magazine.html" rel="alternate" type="text/html" title="使用Fiddler嗅探Android App网络流量并还原大象公会RESTful API" /><published>2018-05-21T00:00:00+00:00</published><updated>2018-05-21T00:00:00+00:00</updated><id>https://cyberloginit.com//2018/05/21/sniff-android-app-traffic-with-fiddler-and-uncover-restful-api-of-elephant-magazine</id><content type="html" xml:base="https://cyberloginit.com//2018/05/21/sniff-android-app-traffic-with-fiddler-and-uncover-restful-api-of-elephant-magazine.html">&lt;h1 id=&quot;使用fiddler嗅探android-app网络流量并还原大象公会restful-api&quot;&gt;使用Fiddler嗅探Android App网络流量并还原大象公会RESTful API&lt;/h1&gt;

&lt;h2 id=&quot;缘由&quot;&gt;缘由&lt;/h2&gt;
&lt;p&gt;很喜欢大象公会的文章，很讨厌微信公众号这种封闭平台。&lt;/p&gt;

&lt;p&gt;但其首要的文章发布平台是微信，还好&lt;a href=&quot;http://idaxiang.org/&quot;&gt;官网&lt;/a&gt;也提供&lt;a href=&quot;http://idaxiang.org/idaxiang_v2.1.1_2017-05-24_00000.apk&quot;&gt;Android App&lt;/a&gt;下载。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;吐槽：&lt;/strong&gt;官网没有HTTPS保护；Android App没有上架Google Play Store，还好提供直接下载链接，而不是像&lt;a href=&quot;http://www.vice.cn&quot;&gt;Vice中国&lt;/a&gt;那样放在第三方“应用商店”，然而下载链接也未做HTTPS保护。&lt;/p&gt;

&lt;p&gt;手机启用未知安装来源(Unknown sources)，安装大象公会Apk，发现&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/blocked_by_play_protect.png&quot; alt=&quot;Blocked by Play Protect&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;This app can collect data that may be used to track you.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;由于Apk的下载链接是HTTP，有被篡改或替换的风险。首先排除安装包被替换的可能(毕竟得到的还是大象公会，不是应用宝。。。)；其次，运营商暂时没有对安装包注入恶意代码的需求；所以，应该是因为大象公会Android App接入了国内某些统计SDK，这种情况比较常见。&lt;/p&gt;

&lt;p&gt;因此，有必要看一下大象公会的Android App究竟如何与服务器交互，为后面第三方客户端的开发做基础。&lt;/p&gt;

&lt;h2 id=&quot;嗅探&quot;&gt;嗅探&lt;/h2&gt;

&lt;p&gt;嗅探Android App HTTP数据包主要有两种方法：&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;在Android本地嗅探，工具如&lt;a href=&quot;https://play.google.com/store/apps/details?id=app.greyshirts.sslcapture&quot;&gt;Packet Capture&lt;/a&gt;；&lt;/li&gt;
  &lt;li&gt;在网络传输过程中嗅探，如PC代理，经典工具有&lt;a href=&quot;https://www.telerik.com/fiddler&quot;&gt;Fiddler&lt;/a&gt;, &lt;a href=&quot;https://www.charlesproxy.com/&quot;&gt;Charles&lt;/a&gt;, &lt;a href=&quot;https://portswigger.net/burp&quot;&gt;Burp suite&lt;/a&gt;；&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Fiddler, Charles, Burp suite等工具嗅探Android App流量的原理都一样，即联网的PC安装上述客户端，在局域网内提供HTTP代理，设置Android手机Wi-Fi流量走该代理。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/android_wifi_http_proxy.png&quot; alt=&quot;Android Wi-Fi HTTP Proxy&quot; /&gt;&lt;/p&gt;

&lt;p&gt;之前一直用&lt;a href=&quot;https://portswigger.net/burp&quot;&gt;Burp suite&lt;/a&gt;，但其更着重捕获，而非监听，所以要设置放行规则，本次需求中体验较差，故使用Fiddler。&lt;/p&gt;

&lt;p&gt;Fiddler需要先Allow remote computers to connect&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/fiddler_proxy.png&quot; alt=&quot;Fiddler Proxy&quot; /&gt;&lt;/p&gt;

&lt;p&gt;端口即Android设置Wi-Fi HTTP Proxy时填的端口。&lt;/p&gt;

&lt;p&gt;然后，PC本机的流量及使用Fiddler HTTP代理的流量都会显示。&lt;/p&gt;

&lt;h2 id=&quot;restful-api&quot;&gt;RESTful API&lt;/h2&gt;

&lt;p&gt;打开大象公会App，刷新或者点击单篇文章，Fiddler中出现对应的RESTFul请求，否定了之前的猜测：文章存储在微信公众号，客户端只是套壳浏览器。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/elephant_magazine.png&quot; alt=&quot;Elephant Magazine&quot; /&gt;&lt;/p&gt;

&lt;p&gt;看来大象公会网站已经实现了完整的RESTful API，提供Web网页很容易，不清楚为什么没有提供，毕竟Web是这个时代最开放的平台。&lt;/p&gt;

&lt;p&gt;获取文章列表API：&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;http://app.idaxiang.org/api/v1_0/art/list?pageSize=20
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;pageSize指定返回的文章条目数量：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;{
    &quot;body&quot;: {
        &quot;ad&quot;: {
            &quot;welcome_ad&quot;: &quot;0&quot;,
            &quot;article_ad&quot;: &quot;0&quot;,
            &quot;css_version_code&quot;: &quot;1&quot;
        },
        &quot;article&quot;: [
            {
                &quot;id&quot;: &quot;1071&quot;,
                &quot;title&quot;: &quot;唐朝真的「对外开放」吗？&quot;,
                &quot;headpic&quot;: &quot;http://static.idaxiang.org/fb875f7f0d51225ff62afb3492845c22_thumb.jpeg&quot;,
                &quot;raw_headpic&quot;: &quot;http://static.idaxiang.org/fb875f7f0d51225ff62afb3492845c22.jpeg&quot;,
                &quot;author&quot;: &quot;石禄珊&quot;,
                &quot;brief&quot;: &quot;唐朝的「对外开放」，是一种「外面的能进来，里面的难出去，进来了休想走」的开放。&quot;,
                &quot;read_num&quot;: &quot;2457&quot;,
                &quot;wechat_url&quot;: &quot;https://mp.weixin.qq.com/s?__biz=MjM5NzQwNjcyMQ==&amp;amp;mid=2651015947&amp;amp;idx=1&amp;amp;sn=8c0fd661ffb13ba8641d956a3279985b&amp;amp;chksm=bd2d9a658a5a13735e19a78664f28bf554eed56e1f26fd6a13b8684dba7673ca543e79039c64#rd&quot;,
                &quot;url&quot;: &quot;&quot;,
                &quot;create_time&quot;: &quot;1526486400&quot;,
                &quot;update_time&quot;: &quot;1526567239&quot;
            },
            {
                &quot;id&quot;: &quot;1070&quot;,
                &quot;title&quot;: &quot;南怀瑾的江湖&quot;,
                &quot;headpic&quot;: &quot;http://static.idaxiang.org/bacf201ecbaf03e61fadf6027dad7e4d_thumb.jpeg&quot;,
                &quot;raw_headpic&quot;: &quot;http://static.idaxiang.org/bacf201ecbaf03e61fadf6027dad7e4d.jpeg&quot;,
                &quot;author&quot;: &quot;李青岚&quot;,
                &quot;brief&quot;: &quot;他以绝大机缘和自身禀赋，在特殊的历史行程里占据了一个独一无二的生态位。南怀瑾可以成为「国学大师」，但国学大师绝不可能成为南怀瑾。&quot;,
                &quot;read_num&quot;: &quot;1815&quot;,
                &quot;wechat_url&quot;: &quot;https://mp.weixin.qq.com/s?__biz=MjM5NzQwNjcyMQ==&amp;amp;mid=2651015925&amp;amp;idx=1&amp;amp;sn=a64dab30eff2ec6f9e9f9c0ef735acc1&amp;amp;chksm=bd2d9b9b8a5a128d0310124939d393b605c6de66b621e63998ad625161a0c0d8c339718107e6#rd&quot;,
                &quot;url&quot;: &quot;&quot;,
                &quot;create_time&quot;: &quot;1526400000&quot;,
                &quot;update_time&quot;: &quot;1526567348&quot;
            }
        ]
    },
    &quot;head&quot;: {
        &quot;code&quot;: 0,
        &quot;message&quot;: &quot;&quot;,
        &quot;has_more&quot;: true
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;获取指定文章API：&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;http://app.idaxiang.org/api/v1_0/art/info?id=400
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;id即文章ID，返回指定文章内容：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;{
    &quot;body&quot;: {
        &quot;article&quot;: {
            &quot;id&quot;: &quot;400&quot;,
            &quot;title&quot;: &quot;上海为什么缺少创业家&quot;,
            &quot;headpic&quot;: &quot;http://static.idaxiang.org/d6973a16ee62198c80127569b6e03e43_thumb.jpg&quot;,
            &quot;raw_headpic&quot;: &quot;http://static.idaxiang.org/d6973a16ee62198c80127569b6e03e43.jpg&quot;,
            &quot;author&quot;: &quot;高利民&quot;,
            &quot;brief&quot;: &quot;上海是中国政府管理能力、效率和服务意识最好的城市，而且也是人才引进奖励制度最完善、规范的城市，但这些优点，有事恰恰妨碍出现创业者。&quot;,
            &quot;content&quot;: &quot;&amp;lt;h5&amp;gt;&amp;lt;span&amp;gt;上海是中国政府管理能力、效率和服务意识最好的城市，而且也是人才引进奖励制度最完善、规范的城市，但这些优点，有事恰恰妨碍出现创业者。&amp;lt;/span&amp;gt;&amp;lt;/h5&amp;gt;&amp;lt;p&amp;gt;你能想起几个最近十年在上海崛起的民营企业品牌？&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;几乎没有。如果换做北京、广东、福建、浙江，许多人都能至少说出一些。&amp;lt;/p&amp;gt;&amp;lt;p style=\&quot;text-align: center;\&quot;&amp;gt;&amp;lt;img src=\&quot;http://static.idaxiang.org/266f989922b96aaaf57c16a4ad4f35b6.jpeg\&quot;/&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;span&amp;gt;2014中国民营企业500强各省区市企业数量&amp;lt;/span&amp;gt;&amp;lt;/h6&amp;gt;&amp;lt;p&amp;gt;这是令上海倍感尴尬的一点：作为一直以来中国内地的经济中心，上海聚集了大量跨国企业、著名国企、民营企业的中国区总部，几乎能找到所有世界知名企业。但却极少有本土的创业企业，也很少生长著名的品牌、专利。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;上海规模民营企业，大都集中在传统制造业和商业领域，极少有高科技型企业。以专利数量论，北京专利数仅次于广东，但每万人拥有的有效专利数则高居全国第一，接近上海的2倍。即使刨去其中国家科研院所的成分，其绝对领先也不容置疑。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;那么，水面下的冰山呢？截止2013年末，中国各地注册商标数排名是：广东（112.7 万）、浙江（86.4 万）、北京（46.7 万）、江苏（45.9 万）、福建（40 万）、上海（36.4万）。人口多于北京的上海却被北京拉开了相当大的距离。&amp;lt;/p&amp;gt;&amp;lt;p style=\&quot;text-align: center;\&quot;&amp;gt;&amp;lt;span&amp;gt;&amp;lt;img src=\&quot;http://static.idaxiang.org/396800832765969b23937e4ed40f5bd9.jpeg\&quot;/&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;span&amp;gt;截止2011年部分省市有效发明专利量及万人发明专利拥有量情况&amp;lt;/span&amp;gt;&amp;lt;/h6&amp;gt;&amp;lt;p&amp;gt;然而，在中国城市中，上海却是公认政府管理最精细、效率最高、服务意识最好的城市，为吸引人才、鼓励创新不遗余力。或许，正是这种强烈反差，才会有2008年时任上海市委书记的俞正声著名的俞氏一问：上海为什么不出马云？&amp;lt;/p&amp;gt;&amp;lt;h2&amp;gt;缺乏空间的土壤&amp;lt;/h2&amp;gt;&amp;lt;p&amp;gt;其实，早期的上海也曾是创业家的乐园。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;19世纪中期后，上海先后设立了英、法、美等国租界，逐渐形成了脱离于清政府权力，又享有国际交往的独立空间，最早接触到了近代化的经济组织形式。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;此后，上海逐步成为远东的经济、贸易中心之一，无数冒险者来到这片十里洋场，虽然当时的人们并不将此称为“创业”，但许多工厂、商行都在此产生。&amp;lt;/p&amp;gt;&amp;lt;p style=\&quot;text-align: center;\&quot;&amp;gt;&amp;lt;span&amp;gt;&amp;lt;img src=\&quot;http://static.idaxiang.org/daa06d095bc36d3907a41e12b3306a00.jpeg\&quot;/&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;span&amp;gt;1928年的上海公共租界外滩一景&amp;lt;/span&amp;gt;&amp;lt;/h6&amp;gt;&amp;lt;p&amp;gt;真正的变化产生于1949年以后。由于上海出色的经济基础，被作为公私合营、货币改制等新政的重点地区。上海和工业基础同样雄厚的东北一样，建立了远比其他地区更完备的公有制体系。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;这时的上海经济到底比其他地区高出多少？&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;即使经历了“三线建设”等为中西部输血的过程，上海仍在改革开放前占全国工业总产值的三分之一左右。它在计划经济中的地位，使之今日依然保有强大的国有经济体系。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;熟悉上海的外地人应该注意到一个现象：上海今天的国营商业企业依然无处不在。以超市为例，上海的社区型超市主要是联华与华联（现已合并为一家），两者均为商业局下属，比它们更小且遍布街巷的国字号超市还有可的、好德等。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;中国几乎不会有第二个城市，国营超市占据如此重要的地位。与超市毗邻的，还有很多国营饭馆甚至理发馆——有些饭馆严格坚持每天8小时劳动，午后有两小时午休。不可思议的是，有些民营餐馆会让你觉得是国营的，里面的服务人员不是外地小姑娘，而是一群本地阿姨。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;这当然是50年代后公有制改造的后果，但其格局延续至今，还有赖于上海在经济体制转型中对就业问题的出色解决——它几乎没有经历过其他相似城市那种剧烈的下岗社会镇痛。其他地方转轨过程中常出现的国有资产流失问题，在上海引起的争议也非常小。&amp;lt;/p&amp;gt;&amp;lt;p style=\&quot;text-align: center;\&quot;&amp;gt;&amp;lt;span&amp;gt;&amp;lt;img src=\&quot;http://static.idaxiang.org/5c2537b16fe5896ed754d691c98cf4a3.jpeg\&quot;/&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;span&amp;gt;1956年，毛泽东在荣毅仁陪同下参观上海中新纺织厂&amp;lt;/span&amp;gt;&amp;lt;/h6&amp;gt;&amp;lt;p&amp;gt;与其鲜明相对的是重工业盛极一时的东北。这很大程度上得益于上海市政府官员卓越的管理能力。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;不过，这却日渐显示出了另一面的效应——给新企业、新经济势力留出的空间太小了。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;中国民营企业具有强大创新能力和社会活力的地区，无一例外都是国营企业不成气候，计划经济体制薄弱的地方。中国国企比重较大的地区，国企多仰赖银行低息贷款及国家特许政策等优惠维系，而上海则仰赖高昂的地价，这使它们相对更理直气壮，拥有无处不在的话事权。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;为谋求稳定的市场地位，它们很容易通过政府制定各种细密的管治措施，构建维护垄断地位的堤坝。而创业行为，本质上打破行业格局的洗牌行为，它当然为地位稳固者所不容。像“滴滴专车”最近被上海市交管局叫停这种事发生在上海，其实并不意外。&amp;lt;/p&amp;gt;&amp;lt;h2&amp;gt;五道口与张江科技园&amp;lt;/h2&amp;gt;&amp;lt;p&amp;gt;上海并不是没有意识到这一点。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;1980年以后，上海经济增长速度放缓，其经济中心的地位受到浙江、广东、福建的挑战。直到九零年决定开发浦东新区，上海才在接下来的十多年保持了10%以上的增长，重新确立了自己在全国经济中的地位。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;这也给上海市应对创业问题提供了思路——典型的例子就是精心规划设计的张江高科技园区。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;为了形成像北京海淀区那样的人才集聚效应，科技园区与新大学园区被安排得很近。这里的马路极为宽阔，马路两旁是整齐、漂亮的园区建筑，但几乎没有生活气息，看上去很像一块北京的飞地。&amp;lt;/p&amp;gt;&amp;lt;p style=\&quot;text-align: center;\&quot;&amp;gt;&amp;lt;img src=\&quot;http://static.idaxiang.org/78bfc9381eb8daa0efd382792e8145ba.jpeg\&quot;/&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;h6&amp;gt;上海张江高科技园区&amp;lt;/h6&amp;gt;&amp;lt;p&amp;gt;问题是，这块精心设计的园区，只适合已成规模的企业入驻，而不是在这里创业。一般的创业者很难在此找到合适的低成本住房、餐饮等条件。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;如果类比北京海淀的五道口，这种精心的规划其实是不利于创业的。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;五道口之所以成为怀抱IT创业梦者心中的“宇宙中心”，除了周边高校和IT企业云集外，附近多为小而老旧的小区，少有大规模的高档社区，一到晚上满街摊贩。热闹、拥挤而富于生活气息的五道口，是最不像北京的地方，倒像是老上海在北京的一块飞地，但可为梦想家们提供就近且便利廉价的栖息条件，如果实在没钱，他们甚至可以混进学校宿舍。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;如果中关村和五道口像张江高科技园区一样，宽阔的马路两旁只有敞亮巨大的办公室，街道上看不见闲杂人员，一到下班时间，大家就一哄而散赶路回家，它断不会像今天这样每天诞生无数的创意和新企业。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;上海浦东陆家嘴金融中心的街道规划方式，也被批评为大而无当——华尔街摩天大楼之间的街道非常狭窄，临街密布着咖啡馆之类的谈话场所，两栋写字楼里的生意人突然有想法时，可以非常便利地约谈碰撞，而陆家嘴那些写字楼里的人，要和对面大楼的人当面交流，必须横过极为宽阔的马路，是绕远路，还是打出租车，颇费思量。&amp;lt;/p&amp;gt;&amp;lt;p style=\&quot;text-align: center;\&quot;&amp;gt;&amp;lt;img src=\&quot;http://static.idaxiang.org/bd8d5aaa2596917ae54356831bb6e099.jpeg\&quot;/&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;h6&amp;gt;从纽约曼哈顿东部的克莱斯勒大楼向下看，纽约的街道与上海浦东新区相比十分狭窄&amp;lt;/h6&amp;gt;&amp;lt;p&amp;gt;好在上海市政府注意到了这个批评，于是有了一个可以不用横过马路的补救措施，在几栋摩天大楼之间修了一个巨大的陆家嘴天桥。可惜辽阔的张江科技园就很难照此办理了。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;创业者需要的往往是一种宽松的环境，成本低廉，又在空间上充满联系，容易沟通。这是规划者最不擅长的事情——历史上，没有几个创业中心是规划出来的。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;而且，也并没有哪些人从出生起就带着创业者的标签。创业企业、创业者往往诞生于复杂的交汇之中，新增的城市移民、高校毕业生中创业比例都很高。&amp;lt;/p&amp;gt;&amp;lt;p style=\&quot;text-align: center;\&quot;&amp;gt;&amp;lt;img src=\&quot;http://static.idaxiang.org/95609da1b8ad9b769564fe3a5981135d.jpeg\&quot;/&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;h6&amp;gt;陆家嘴天桥&amp;lt;/h6&amp;gt;&amp;lt;p&amp;gt;上海自然知道这些人的重要性。它们也有着全国最优秀的人才引进制度，其积分方案、居住证福利在全国绝对属于一流。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;但这种优秀制度反而引起了一些负面效果。&amp;lt;/p&amp;gt;&amp;lt;h2&amp;gt;被“格式化”的上海梦&amp;lt;/h2&amp;gt;&amp;lt;p&amp;gt;1992年，上海常住人口是1280万，到2013年底，上海常住人口为2415万，11年净增了1100多万人，新移民占总人口数的47%。&amp;lt;/p&amp;gt;&amp;lt;p style=\&quot;text-align: center;\&quot;&amp;gt;&amp;lt;span&amp;gt;&amp;lt;img src=\&quot;http://static.idaxiang.org/aa5d572a77d89962dd0085577c35b7fd.jpeg\&quot;/&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;span&amp;gt;上海市人口年龄结构与国际通用年龄结构的对比&amp;lt;/span&amp;gt;&amp;lt;/h6&amp;gt;&amp;lt;p&amp;gt;但是，深圳同样新增1000万移民，里面出现了任正非、马化腾等登上世界级舞台的创业者。而上海新移民中，却没有同等量级的创业家。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;如果对上海、北京、广州、深圳新移民做一项奋斗梦想的问卷调查，或许“上海梦”最单调实际，那就是房子。北京、深圳的梦想就要五花八门得多。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;上海是引领中国房价的龙头，并且是中国第一个因住房价格高涨出现全民炒房现象的城市。“炒房”重塑了上海人的观念，它不但是上海人日常交流的必谈话以甚至成为衡量成就的重要标签。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;房价贵使得1980年代以前普遍有房的上海人突如其来地享受到了“存量涨停”的福利，这笔意外的财富保障使得老上海人和老北京人、老广州人一样不思进取。&amp;lt;/p&amp;gt;&amp;lt;p style=\&quot;text-align: center;\&quot;&amp;gt;&amp;lt;img src=\&quot;http://static.idaxiang.org/61b26b2646d4b9166cd1401058cf8951.jpeg\&quot;/&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;h6&amp;gt;1999—2010，上海房价与人均月薪走势图&amp;lt;/h6&amp;gt;&amp;lt;p&amp;gt;对上海新移民来说，2008年前后，则是一条分界线。2008年前成功买房落沪的人，是“房产红利”的最大得利族群，他们许多人通过买房攒房完成了真正意义上的“原始积累”。2008年之后来沪的人，“落户”一夜之间变成了“为房子而活的战争”。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;对新移民来说，上海住房问题的影响来得远比广州、深圳甚至北京严重。深圳、广州有大量城中村，北京虽然较少城中村，但其市政、社区和小区物业管理远不如上海精细，虽然近年开始学习上海整治群租以及在住宅区办公司的现象，但死角比上海要多得多。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;这让新移民的个人发展受到极大限制——没有低价栖身的空间。当然，人们也可以认为，没有低价住房，筛掉的大多是素质不那么高的人才，上海需要的是高素质人才。&amp;lt;/p&amp;gt;&amp;lt;p style=\&quot;text-align: center;\&quot;&amp;gt;&amp;lt;span&amp;gt;&amp;lt;img src=\&quot;http://static.idaxiang.org/bb6711ae6f2223bd4802c575a29bf4b0.jpeg\&quot;/&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;span&amp;gt;白石洲，深圳最大的城中村，多年来成为了来深打拼人员的聚集地&amp;lt;/span&amp;gt;&amp;lt;/h6&amp;gt;&amp;lt;p&amp;gt;为吸引外地高素质人才，上海推出了提供留居上海的各项激励措施，按2002年相关规则，获得居住证七年后可申请上海户籍。相比其他城市的粗放简单，上海人以其特有的精密、认真，拿出一套“国内人才申领《上海市居住证》打分表”，使规则变得更清晰、透明，能极大程度地消灭作弊空间。这使得只有上海的居住证才是被外地新移民积极认真对待的。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;但是，上海金融与法律研究院在承接《户籍的成本》课题时，仔细研读这个打分机制对人才的激励作用，他们得出这样一个结论，它实际上鼓励的是外来人才安心打工，而不是创业。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;譬如，受聘的薪水、岗位级别、纳税数额、社保缴纳越高，得分越高，它当然是“甄别人才”的合理衡量标准，但却会让一个积分很高的人在面临创业机会时，陷入选择困境——在离居住证、上海户籍只有一步之遥时，创业往往意味着前功尽弃，毕竟白手起家创业期间，在薪水、纳税额、社保缴纳的得分都会大幅下降。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;虽然《上海市居住证》打分表中，有“人才在沪投资创业附加分”，但它的打分奖励全部是以投资额和雇佣本地人数来计算的，实际鼓励的是外地资本在上海办企业，而不是在上海白手起家创业。这与通常人们说的创业完全不是一回事。&amp;lt;/p&amp;gt;&amp;lt;p style=\&quot;text-align: center;\&quot;&amp;gt;&amp;lt;img src=\&quot;http://static.idaxiang.org/4cae61e5191a2627cef2023aa09ba238.png\&quot;/&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;span&amp;gt;某上海教育机构打出的招生广告&amp;lt;/span&amp;gt;&amp;lt;/h6&amp;gt;&amp;lt;p&amp;gt;有趣的是，《上海市居住证积分办法细则》中“职称”依然占了很大权重，除了特殊技术岗位，职称对民营机构组织来说，没有任何价值，但这套打分体系，会使得不在国营单位的新移民，为了居住证去浪费时间报考“经济师”这类毫无用处的职称。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;前面提到的房子，同样是打分项目，买房加分，它起到了与房价上涨的相同作用——有钱立即买房。&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;所以，我们一点不难理解，新移民的“上海梦”是高度格式化的：房子。至于创业，最好还是到北京、深圳去碰碰运气吧。&amp;lt;/p&amp;gt;                    &quot;,
            &quot;read_num&quot;: &quot;2689&quot;,
            &quot;wechat_url&quot;: &quot;http://mp.weixin.qq.com/s?__biz=MjM5NzQwNjcyMQ==&amp;amp;mid=209551190&amp;amp;idx=1&amp;amp;sn=ce028395392990019b94830e4860da77#rd&quot;,
            &quot;url&quot;: &quot;&quot;,
            &quot;create_time&quot;: &quot;1419955200&quot;,
            &quot;update_time&quot;: &quot;1437653110&quot;
        }
    },
    &quot;head&quot;: {
        &quot;code&quot;: 0,
        &quot;message&quot;: &quot;&quot;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;很容易发现&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;body.article.content&lt;/code&gt;中便是HTML编码的文章(包括图片)。&lt;/p&gt;

&lt;p&gt;此外，本文写成时最新的文章id是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1071&lt;/code&gt;，对应”唐朝真的「对外开放」吗？”这篇文章，如果为pageSize赋值1000，返回的文章列表基本上包括了大象公会创立以来的所有文章。&lt;/p&gt;

&lt;p&gt;值得注意的是，文章id大部分情况下是连续的，但也存在连续几百个id没有对应文章的情况，主要集中在238以下，不清楚是API设计者有意为之(留作他用)，还是一些id对应的文章在审查的压力下被迫删除(一些高位的id)。&lt;/p&gt;

&lt;p&gt;大象公会的RESTful API很好的体现了Web平台的开放性，在此基础上可以开发体验更佳的Android/iOS客户端，或是制作RSS订阅源。&lt;/p&gt;</content><author><name></name></author><summary type="html">使用Fiddler嗅探Android App网络流量并还原大象公会RESTful API</summary></entry><entry><title type="html">东信和平USIM卡破解原理及Linux下智能卡渗透笔记</title><link href="https://cyberloginit.com//2018/05/14/eastcompeace-usim-exploit-and-notes-on-smart-card-pentest-for-linux.html" rel="alternate" type="text/html" title="东信和平USIM卡破解原理及Linux下智能卡渗透笔记" /><published>2018-05-14T00:00:00+00:00</published><updated>2018-05-14T00:00:00+00:00</updated><id>https://cyberloginit.com//2018/05/14/eastcompeace-usim-exploit-and-notes-on-smart-card-pentest-for-linux</id><content type="html" xml:base="https://cyberloginit.com//2018/05/14/eastcompeace-usim-exploit-and-notes-on-smart-card-pentest-for-linux.html">&lt;h1 id=&quot;东信和平usim卡破解原理及linux下智能卡渗透笔记&quot;&gt;东信和平USIM卡破解原理及Linux下智能卡渗透笔记&lt;/h1&gt;

&lt;h2 id=&quot;东信和平usim卡破解原理&quot;&gt;东信和平USIM卡破解原理&lt;/h2&gt;

&lt;h3 id=&quot;背景&quot;&gt;背景&lt;/h3&gt;
&lt;p&gt;查找东信和平USIM资料时看到这篇&lt;a href=&quot;https://forum.51nb.com/forum.php?mod=viewthread&amp;amp;tid=1819005https://forum.51nb.com/forum.php?mod=viewthread&amp;amp;tid=1819005&quot;&gt;“利用东信和平卡可编辑的技术，改iccid用有锁iphone手机”&lt;/a&gt;，&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;14年东信和平的usim卡被暴出可以读取卡片的信息&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;读取出卡的数据，重新写入白卡中使用&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;此处“读取出卡的数据”至少能够读出IMSI, Ki, &lt;a href=&quot;https://diameter-protocol.blogspot.com/2013/06/usage-of-opopc-and-transport-key.html&quot;&gt;OP/OPc&lt;/a&gt;，
而Ki在普通鉴权等级(PIN/PUK)下是无法读出的，至少需要ADM鉴权。&lt;/p&gt;

&lt;h3 id=&quot;分析&quot;&gt;分析&lt;/h3&gt;
&lt;p&gt;下载附件“USIM_Explorer改iccid软件.zip”，里面有&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dx.exe&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DesDLL.dll&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;USIM_Explorer.exe&lt;/code&gt;三个可执行文件。&lt;/p&gt;

&lt;p&gt;根据里面某张截图的提示，修改东信和平USIM卡的ICCID需要使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;USIM_Explorer.exe&lt;/code&gt;执行以下命令&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;0020000A08 + 使用`dx.exe`计算出的ADM
00A4000C02 + 3F00
00A4000C02 + 2FE2
00D600000A + ICCID(20个十六进制数字)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;apdu&quot;&gt;APDU&lt;/h4&gt;
&lt;p&gt;关于Smart Card Communication&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Card Acceptance Device(CAD): supply the cards with power&lt;/li&gt;
  &lt;li&gt;half-duplexed communication model&lt;/li&gt;
  &lt;li&gt;master-slave mode: CAD is the master, Card is the slave&lt;/li&gt;
  &lt;li&gt;Application Protocol Data Unit(APDU): ISO 7816-4&lt;/li&gt;
  &lt;li&gt;Command APDU(C-APDU): from CAD to Card&lt;/li&gt;
  &lt;li&gt;Response APDU(R-APDU): from Card to CAD&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/images/command_apdu.png&quot; alt=&quot;Command APDU&quot; /&gt;&lt;/p&gt;

&lt;p&gt;根据APDU规范，每行C-APDU命令的前8个十六进制数字分别对应CLA INS P1 P2，每个字段占一字节，称为Mandatory Header即&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;CLA&lt;/th&gt;
      &lt;th&gt;INS&lt;/th&gt;
      &lt;th&gt;P1&lt;/th&gt;
      &lt;th&gt;P2&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;00&lt;/td&gt;
      &lt;td&gt;20&lt;/td&gt;
      &lt;td&gt;00&lt;/td&gt;
      &lt;td&gt;0A&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;00&lt;/td&gt;
      &lt;td&gt;A4&lt;/td&gt;
      &lt;td&gt;00&lt;/td&gt;
      &lt;td&gt;0C&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;00&lt;/td&gt;
      &lt;td&gt;D6&lt;/td&gt;
      &lt;td&gt;00&lt;/td&gt;
      &lt;td&gt;00&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;CLA: Class of Instruction&lt;/p&gt;

&lt;p&gt;INS: Instruction&lt;/p&gt;

&lt;p&gt;P1, P2: Parameter 1, 2&lt;/p&gt;

&lt;p&gt;后面的字段称为Optional Body，根据Header中的命令需求，分别有：&lt;/p&gt;

&lt;p&gt;LC: Length of Command Data&lt;/p&gt;

&lt;p&gt;Command Data&lt;/p&gt;

&lt;p&gt;LE: Length of Expected Response&lt;/p&gt;

&lt;p&gt;例如&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;00A4000C02 + 3F00
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;00&lt;/code&gt;表示CLS，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A4&lt;/code&gt;表示&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SELECT FILE&lt;/code&gt;命令，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;00&lt;/code&gt;表示&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;select EF, DF or MF by file identifier&lt;/code&gt;，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0C&lt;/code&gt;表示&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;File Control Information(FCI) returned in response&lt;/code&gt;，&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;02&lt;/code&gt;是LC，表示Command Data长度为两字节，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3F00&lt;/code&gt;即MF。&lt;/p&gt;

&lt;p&gt;R-ADPU&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/response_apdu.png&quot; alt=&quot;Response APDU&quot; /&gt;&lt;/p&gt;

&lt;p&gt;SW: Status Word&lt;/p&gt;

&lt;p&gt;例如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;9000&lt;/code&gt;时表示SELECT FILE OK&lt;/p&gt;

&lt;h4 id=&quot;tpdu&quot;&gt;TPDU&lt;/h4&gt;
&lt;p&gt;Transmission Protocol Data Unit&lt;/p&gt;

&lt;p&gt;APDUs are transmitted by TPDUs&lt;/p&gt;

&lt;p&gt;Defined in ISO 7816-3&lt;/p&gt;

&lt;h4 id=&quot;atr&quot;&gt;ATR&lt;/h4&gt;
&lt;p&gt;Answer To Reset&lt;/p&gt;

&lt;p&gt;After smart card is powered up, it sends ATR message to the host&lt;/p&gt;

&lt;p&gt;Up to 33 bytes&lt;/p&gt;

&lt;h4 id=&quot;逆向dxexe&quot;&gt;逆向dx.exe&lt;/h4&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dx.exe&lt;/code&gt;大小为614,400 bytes，简单分析后发现，该程序进行了以下操作&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;00A40000023F00
00A40000022F50
00B000002C
00A40000022F51
00B000000F
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2F50&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2F51&lt;/code&gt;都不是标准的USIM文件EF，猜测为东信和平私有实现。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/dx_exe.png&quot; alt=&quot;dx.exe&quot; /&gt;&lt;/p&gt;

&lt;p&gt;推测&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dx.exe&lt;/code&gt;的工作流程为：点击&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;USIM专用工具单次授权版&lt;/code&gt;后：&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;程序先检查电脑是否连接PS/SC读卡器，否则报错;&lt;/li&gt;
  &lt;li&gt;尝试与USIm卡建立通信，发送&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;00A40000023F00&lt;/code&gt;等指令，读取卡上存储的私有信息(2F50/2F51处的)，如果不成功，报错；&lt;/li&gt;
  &lt;li&gt;根据读取的信息，通过计算模块(IDA中看到一处结构很像加解密模块)计算出ADM key。&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;简单来讲，ADM(Administrative) key是智能卡(Smart Card)文件权限控制中最高级别的key，类似还有PIN(Personal Identification Number), PUK(PIN Unblocking Key)，权限递增。&lt;/p&gt;

&lt;p&gt;如果获得了USIM卡的ADM key，则可以读出Ki，这便是东信和平USIM卡的破解原理：
使用“内部流出”的ADM计算工具获得USIM卡的ADM key，通过ADM key读取卡中的关键信息，如Ki。&lt;/p&gt;

&lt;p&gt;由于时间有限，未完整逆向出ADM key的计算流程。“USIM_Explorer改iccid软件.zip”下载链接在&lt;a href=&quot;https://mega.nz/#!HCYEDZCa!-4StlPXfVnOGYnBlczn5WA0lztzse4StWbTNYTgI5Js&quot;&gt;此&lt;/a&gt;，如果你有兴趣逆向&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dx.exe&lt;/code&gt;，欢迎留言或邮件交流。&lt;/p&gt;

&lt;h2 id=&quot;linux下智能卡渗透笔记&quot;&gt;Linux下智能卡渗透笔记&lt;/h2&gt;
&lt;p&gt;Linux系统通过&lt;a href=&quot;https://pcsclite.apdu.fr/&quot;&gt;PC/SC Lite&lt;/a&gt;支持使用PC/SC(Personal Computer/Smart Card)标准。&lt;/p&gt;

&lt;p&gt;个人主要使用基于Python的&lt;a href=&quot;https://pyscard.sourceforge.io/&quot;&gt;pyscard&lt;/a&gt;及基于此的&lt;a href=&quot;https://osmocom.org/projects/pysim/wiki&quot;&gt;pySim&lt;/a&gt;与USIM卡交互。&lt;/p&gt;

&lt;h3 id=&quot;pysim&quot;&gt;pySim&lt;/h3&gt;
&lt;p&gt;pySim支持串口与PC/SC两种读卡器&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Option&lt;/th&gt;
      &lt;th&gt;Parameter&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;-d&lt;/td&gt;
      &lt;td&gt;Serial Device fo SIM Access [default: /dev/ttyUSB0]&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;-p&lt;/td&gt;
      &lt;td&gt;Which PS/SC number for SIM access&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;注意PS/SC number是执行&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pcsc_scan&lt;/code&gt;后得到的，如：&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Scanning present readers...
0: Identiv SCR35xx USB Smart Card Reader [CCID Interface] (xxxxxxxxxxxxxx) 00 00
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;中的&lt;strong&gt;0&lt;/strong&gt;。&lt;/p&gt;

&lt;h3 id=&quot;adm-key&quot;&gt;ADM key&lt;/h3&gt;
&lt;p&gt;之前的博文&lt;a href=&quot;https://cyberloginit.com/2018/05/03/build-a-lte-network-with-srslte-and-program-your-own-usim-card.html&quot;&gt;Build a LTE Network with srsLTE and Program Your Own USIM Card&lt;/a&gt;中提到了写USIM卡的软件需要和卡配套，其实不完全是这种情况。&lt;/p&gt;

&lt;p&gt;正如前文所讲，写卡最主要的是对ADM key的鉴权，之后写卡命令大部分情况下都是符合智能卡标准的，为pySim增加某些USIM卡写卡支持需要解决两个问题：&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;ADM key获取及ADM key鉴权(某些卡的鉴权方法非标准)；&lt;/li&gt;
  &lt;li&gt;某些非标准参数(通常是Ki)的读写。&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;此处的“非标准”指文件位置或者写卡命令非标准，然而在APDU层面都是标准的(此层以下厂商没有私有的必要，需要花费太多研发精力)。&lt;/p&gt;

&lt;p&gt;分析pySim的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pySim-prog.py&lt;/code&gt;可以看到，pySim支持的如sysmoUSIM-GR1, sysmoUSIM-SJS1等，其实是实现了对这些卡的ADM鉴权及参数写入。&lt;/p&gt;

&lt;p&gt;我们在之前博文中使用的私有写卡软件&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SIM Personalize tools(Copyright: GreenCard Co.,Ltd Ver 3.1.0&lt;/code&gt;很容易逆向，通过strings的搜索，很容易得到此类卡的鉴权APDU，写参数APDU等。&lt;/p&gt;

&lt;p&gt;该软件“支持的”卡其实是ADM key是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&lt;/code&gt;，即&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3838383838383838&lt;/code&gt;长度为16个十六进制数字的值。&lt;/p&gt;

&lt;p&gt;手中的另一个NB-IoT USIM卡的ADM key是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;22222222&lt;/code&gt;，即&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3232323232323232&lt;/code&gt;，ADM key的长度为8 bytes，在APDU中转换成ASCII值，也有某些USIM的ADM值直接以16个十六进制呈现，且没有对应的字符，如上面使用的东信和平USIM卡。&lt;/p&gt;

&lt;h2 id=&quot;reference&quot;&gt;Reference&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://forum.51nb.com/forum.php?mod=viewthread&amp;amp;tid=1819005&quot;&gt;https://forum.51nb.com/forum.php?mod=viewthread&amp;amp;tid=1819005&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://blog.csdn.net/s762888517/article/details/52980312&quot;&gt;https://blog.csdn.net/s762888517/article/details/52980312&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.eftlab.co.uk/index.php/site-map/knowledge-base/118-apdu-response-list&quot;&gt;https://www.eftlab.co.uk/index.php/site-map/knowledge-base/118-apdu-response-list&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://cardwerk.com/smart-card-standard-iso7816-4-section-6-basic-interindustry-commands/&quot;&gt;http://cardwerk.com/smart-card-standard-iso7816-4-section-6-basic-interindustry-commands/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://blog.csdn.net/A493203176/article/details/65445775&quot;&gt;https://blog.csdn.net/A493203176/article/details/65445775&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://osmocom.org/projects/pysim/wiki&quot;&gt;https://osmocom.org/projects/pysim/wiki&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://sourceforge.net/p/openlte/wiki/Programming%20you%20own%20USIM%20card/&quot;&gt;https://sourceforge.net/p/openlte/wiki/Programming%20you%20own%20USIM%20card/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.3gpp.org/dynareport/31102.htm&quot;&gt;TS 31.102&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">东信和平USIM卡破解原理及Linux下智能卡渗透笔记</summary></entry><entry><title type="html">GitHub Pages Jekyll Minima Customize Footer</title><link href="https://cyberloginit.com//2018/05/05/github-pages-jekyll-minima-customize-footer.html" rel="alternate" type="text/html" title="GitHub Pages Jekyll Minima Customize Footer" /><published>2018-05-05T00:00:00+00:00</published><updated>2018-05-05T00:00:00+00:00</updated><id>https://cyberloginit.com//2018/05/05/github-pages-jekyll-minima-customize-footer</id><content type="html" xml:base="https://cyberloginit.com//2018/05/05/github-pages-jekyll-minima-customize-footer.html">&lt;h1 id=&quot;github-pages-jekyll-minima-customize-footer&quot;&gt;GitHub Pages Jekyll Minima Customize Footer&lt;/h1&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;a href=&quot;https://github.com/jekyll/minima&quot;&gt;Minima&lt;/a&gt; is a one-size-fits-all Jekyll theme for writers. It’s Jekyll’s default (and first) theme.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As the name implies, Minima offers minimum features by default.&lt;/p&gt;

&lt;p&gt;To customize the footer, you have to override its default structure.&lt;/p&gt;

&lt;p&gt;At the root of your site, first, create an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_includes&lt;/code&gt; directory and copy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;footer.html&lt;/code&gt; from the &lt;a href=&quot;https://github.com/jekyll/minima&quot;&gt;Minima GitHub repository&lt;/a&gt; into it.&lt;/p&gt;

&lt;p&gt;Then customize &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;footer.html&lt;/code&gt; to your own needs.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;footer class=&quot;site-footer h-card&quot;&amp;gt;
  &amp;lt;data class=&quot;u-url&quot; href=&quot;/&quot;&amp;gt;&amp;lt;/data&amp;gt;

  &amp;lt;div class=&quot;wrapper&quot;&amp;gt;

    &amp;lt;h2 class=&quot;footer-heading&quot;&amp;gt;Cyberloginit&amp;lt;/h2&amp;gt;

    &amp;lt;div class=&quot;footer-col-wrapper&quot;&amp;gt;
      &amp;lt;div class=&quot;footer-col footer-col-1&quot;&amp;gt;
        &amp;lt;ul class=&quot;contact-list&quot;&amp;gt;
          &amp;lt;li class=&quot;p-name&quot;&amp;gt;Cyberloginit&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a class=&quot;u-email&quot; href=&quot;mailto:cyberloginit#protonmail.com&quot;&amp;gt;cyberloginit#protonmail.com&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;
      &amp;lt;a href=&quot;https://m.do.co/c/de1b31930850&quot; target=&quot;_blank&quot;&amp;gt;&amp;lt;img src=&quot;/images/DO_Powered_by_Badge_black.svg&quot; &amp;gt;&amp;lt;/a&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div class=&quot;footer-col footer-col-2&quot;&amp;gt;
        &amp;lt;ul style=&quot;list-style-type:none&quot;&amp;gt;
          &amp;lt;li&amp;gt;Friends: &amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;&amp;lt;a href=&quot;https://blog.alalin.me/&quot; target=&quot;_blank&quot;&amp;gt;alalin.me&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div class=&quot;footer-col footer-col-3&quot;&amp;gt;
        &amp;lt;p&amp;gt;Cyber Log in IT.&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

  &amp;lt;/div&amp;gt;

&amp;lt;/footer&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In my case, the social networks column is not needed, so I used it for link exchange.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;div class=&quot;footer-col footer-col-2&quot;&amp;gt;
  &amp;lt;ul style=&quot;list-style-type:none&quot;&amp;gt;
    &amp;lt;li&amp;gt;Friends: &amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;&amp;lt;a href=&quot;https://blog.alalin.me/&quot; target=&quot;_blank&quot;&amp;gt;alalin.me&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
  &amp;lt;/ul&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;VS&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;div class=&quot;footer-col footer-col-2&quot;&amp;gt;&amp;lt;ul class=&quot;social-media-list&quot;&amp;gt;&amp;lt;/ul&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I also added my DigitalOcean referral link.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;div class=&quot;footer-col-wrapper&quot;&amp;gt;
  &amp;lt;div class=&quot;footer-col footer-col-1&quot;&amp;gt;
        ...&amp;lt;li&amp;gt;&amp;lt;a class=&quot;u-email&quot; href=&quot;mailto:cyberloginit#protonmail.com&quot;&amp;gt;cyberloginit#protonmail.com&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;
+ &amp;lt;a href=&quot;https://m.do.co/c/de1b31930850&quot; target=&quot;_blank&quot;&amp;gt;&amp;lt;img src=&quot;/images/DO_Powered_by_Badge_black.svg&quot; &amp;gt;&amp;lt;/a&amp;gt;
  &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can download the official DigitalOcean logo &lt;a href=&quot;https://www.digitalocean.com/press/&quot;&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Last, commit and git push. There you have it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/minima_customized_footer.png&quot; alt=&quot;Customized Footer&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Our customized &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_includes/footer.html&lt;/code&gt; here will overide the default &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;footer.html&lt;/code&gt; used by Minima.&lt;/p&gt;

&lt;p&gt;Besides, You can also customize the CSS style.&lt;/p&gt;

&lt;h2 id=&quot;reference&quot;&gt;Reference&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/jekyll/minima&quot;&gt;https://github.com/jekyll/minima&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://jekyll.github.io/minima/&quot;&gt;https://jekyll.github.io/minima/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">GitHub Pages Jekyll Minima Customize Footer</summary></entry><entry><title type="html">Build a LTE Network with srsLTE and Program Your Own USIM Card</title><link href="https://cyberloginit.com//2018/05/03/build-a-lte-network-with-srslte-and-program-your-own-usim-card.html" rel="alternate" type="text/html" title="Build a LTE Network with srsLTE and Program Your Own USIM Card" /><published>2018-05-03T00:00:00+00:00</published><updated>2018-05-03T00:00:00+00:00</updated><id>https://cyberloginit.com//2018/05/03/build-a-lte-network-with-srslte-and-program-your-own-usim-card</id><content type="html" xml:base="https://cyberloginit.com//2018/05/03/build-a-lte-network-with-srslte-and-program-your-own-usim-card.html">&lt;h1 id=&quot;build-a-lte-network-with-srslte-and-program-your-own-usim-card&quot;&gt;Build a LTE Network with srsLTE and Program Your Own USIM Card&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://upload.wikimedia.org/wikipedia/commons/d/d7/Evolved_Packet_Core.svg&quot; alt=&quot;LTE&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;requirements&quot;&gt;Requirements&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;A Linux (preferably Ubuntu 16.04.4 desktop 64-bit) machine (i5 Dual-Core CPU will do, preferably with a USB 3.0 port)&lt;/li&gt;
  &lt;li&gt;A Software-defined radio (SDR) board with Ettus Universal Hardware Driver (UHD) or the bladeRF driver support, like USRP B210&lt;/li&gt;
  &lt;li&gt;A Windows machine to run the closed source USIM card programming software&lt;/li&gt;
  &lt;li&gt;A &lt;a href=&quot;https://en.wikipedia.org/wiki/PC/SC&quot;&gt;PC/SC&lt;/a&gt; compatible SIM card reader, like the MCR3512&lt;/li&gt;
  &lt;li&gt;A USIM card compatible with the programming software&lt;/li&gt;
  &lt;li&gt;A LTE handset, like the Oneplus One&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;build&quot;&gt;Build&lt;/h2&gt;
&lt;blockquote&gt;
  &lt;p&gt;srsLTE is a free and open-source LTE software suite developed by SRS (www.softwareradiosystems.com).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Of the three well-known open source LTE stack(openLTE, srsLTE and OpenAirInterface), I find srsLTE have both the code elegance of openLTE and the completeness of OpenAirInterface.&lt;/p&gt;

&lt;p&gt;With srsLTE, we are able to run a LTE network(eNodeB, MME, HSS and S/P-GW) on a single pc.&lt;/p&gt;

&lt;p&gt;On a freshly installed 64-bit Ubuntu 16.04.4 desktop machine, install the required libraries with:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo apt-get install cmake libfftw3-dev libmbedtls-dev libboost-program-options-dev libconfig++-dev libsctp-dev

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then install the UHD driver for our USRP B210:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo apt-get install libuhd-dev libuhd003 uhd-host
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next, download and build srsLTE in the home directory with a non-root user:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd ~
git clone https://github.com/srsLTE/srsLTE.git
cd srsLTE
mkdir build
cd build
cmake ../
make
make test
sudo make install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;configuration&quot;&gt;Configuration&lt;/h2&gt;
&lt;p&gt;Change back to the source directory.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd ~/srsLTE
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;srsepc&quot;&gt;srsEPC&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cp srsepc/epc.conf.example srsepc/epc.conf
cp srsepc/user_db.csv.example srsepc/user_db.csv
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;srsenb&quot;&gt;srsENB&lt;/h3&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cp srsenb/enb.conf.example srsenb/enb.conf
cp srsenb/rr.conf.example srsenb/rr.conf
cp srsenb/sib.conf.example srsenb/sib.conf
cp srsenb/drb.conf.example srsenb/drb.conf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;run&quot;&gt;Run&lt;/h2&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd ~/srsLTE/srsepc
sudo srsepc epc.conf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Open another terminal:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd ~/srsLTE/srsenb
sudo srsenb enb.conf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can also tweak the epc.conf or the enb.conf file, like change the MCC and the MNC, or the DNS address.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The UE database file(user_db.csv) has to be within the same directory where you would run the srsepc command.&lt;/p&gt;

&lt;p&gt;Search ‘Available networks’ from your phone, and you should seen the custom built 4G network among local networks.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ue_search_network.png&quot; alt=&quot;Networks&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;usim-card&quot;&gt;USIM Card&lt;/h2&gt;
&lt;p&gt;USIM card is a complex closed system.&lt;/p&gt;

&lt;p&gt;Usually, you will not be able to program a blank USIM card bought online with a open source software like &lt;a href=&quot;https://github.com/osmocom/pysim&quot;&gt;pySim&lt;/a&gt;, 
because different manufacturers have different implementations for the USIM standard.&lt;/p&gt;

&lt;p&gt;If you do not have USIM cards supported by pySIM, like &lt;a href=&quot;http://shop.sysmocom.de/products/sysmousim-sjs1&quot;&gt;sysmoUSIM-SJS1&lt;/a&gt;, GrcardSIM, GrcardSIM2 and MagicSIM, 
a closed source software is needed, and most of the time, it is based on Windows.&lt;/p&gt;

&lt;p&gt;Another way is to simply ask the seller to program the USIM cards for you. Both eBay and Taobao have plenty of them.&lt;/p&gt;

&lt;p&gt;Just make sure the parameters: ICCID, IMSI, KI and OP/OPc are programmed accordingly.&lt;/p&gt;

&lt;h3 id=&quot;save-150&quot;&gt;Save 150￥&lt;/h3&gt;
&lt;p&gt;I bought a USIM card from &lt;a href=&quot;https://item.taobao.com/item.htm?id=564708442949&quot;&gt;Taobao&lt;/a&gt; which costs me 30￥. The USIM card reader and the programming software combined costs up to 150￥.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/taobao.jpg&quot; alt=&quot;USIM&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Note: If this link should fail, just search ‘openlte’ from Taobao.&lt;/p&gt;

&lt;p&gt;So it seems that I will have to spend at least 180￥ for this.&lt;/p&gt;

&lt;p&gt;Not so fast!&lt;/p&gt;

&lt;p&gt;After digging through CSDN, a programmer website in China, I found a &lt;a href=&quot;https://blog.csdn.net/u013429928/article/details/75319585&quot;&gt;interesting article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The USIM programming software used by the blogger is the same as the picture from the Taobao shop, although the later one is heavily watermarked.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/sim_personalize_tools.jpg&quot; alt=&quot;USIM programming software&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Both screenshots show that the USIM programming software is called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SIM Personalize tools(Copyright: GreenCard Co.,Ltd Ver 3.1.0)&lt;/code&gt;. They are even of the same version!&lt;/p&gt;

&lt;p&gt;The blogger has uploaded both a configuration file and a programing software to CSDN, but only gives the download link to the &lt;a href=&quot;https://download.csdn.net/download/u013429928/10137875&quot;&gt;parameters configuration file&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I have managed to find the download link for the programing software &lt;a href=&quot;https://download.csdn.net/download/u013429928/10125492&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Unfortunately, like most Chinese websites, CSDN requires credits to download.&lt;/p&gt;

&lt;p&gt;Fortunately, there are many sellers on Taobao offering CSDN downloading service which costs less than 3￥ for however many credits CSDN requires.&lt;/p&gt;

&lt;p&gt;To save trouble, I have decided to offer it &lt;a href=&quot;https://mega.nz/#!KG5VCSxI!W8-nxXkc5cqQ8Bk1GFvinyNltKJuMZ7kgTIk-xCKaBs&quot;&gt;here&lt;/a&gt;. You’d better have it scanned by some antivirus software for safety concern:)&lt;/p&gt;

&lt;p&gt;As for the USIM reader, any PC/SC compatible smart card reader will do.&lt;/p&gt;

&lt;h3 id=&quot;program-the-usim-card&quot;&gt;Program the USIM Card&lt;/h3&gt;
&lt;p&gt;On Windows 10, just plug in the smart card reader and Windows will take care of installing the drivers needed.&lt;/p&gt;

&lt;p&gt;Then, open SIM Personalize tools &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GRSIMWrite.exe&lt;/code&gt;, click &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Read Card&lt;/code&gt;, it should be able to read the parameters stored without error.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/programming_card.png&quot; alt=&quot;Programming Card&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Next, write the card as you like.&lt;/p&gt;

&lt;p&gt;For srsLTE, make sure the IMSI, KI and &lt;strong&gt;OP&lt;/strong&gt; values are identical with those in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;user_db.csv&lt;/code&gt; file.&lt;/p&gt;

&lt;h2 id=&quot;enbale-ip-network&quot;&gt;Enbale IP Network&lt;/h2&gt;
&lt;p&gt;With the USIM card programmed above, you should be able to connect to LTE network.&lt;/p&gt;

&lt;p&gt;To surf the Internet:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd ~/srsLTE/srsepc
sudo su
./if_masq.sh [Interface for Internet connection]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;You can get all the network interfaces of your machine with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ifconfig&lt;/code&gt;, make sure you give &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if_masq.sh&lt;/code&gt; the name of the interface which connects to the Internet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; DO NOT run if_masq.sh with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo&lt;/code&gt;, it will not work on Ubuntu.&lt;/p&gt;

&lt;p&gt;srsEPC creates a virtual network interface &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;srs_spgw_sgi&lt;/code&gt; with the IP address &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;172.16.0.0/24&lt;/code&gt;. Your phone should be able to get an IP address like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;172.16.0.2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ue_ip.png&quot; alt=&quot;UE IP&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if_masq.sh&lt;/code&gt; script enables IP forward for our Ubuntu system and masquerades traffic from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;srs_spgw_sgi&lt;/code&gt; by the interface which connects to the Internet.&lt;/p&gt;

&lt;p&gt;Next, add an Access Point Names(APN) in the Cellular network settings of your phone.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ue_apn.png&quot; alt=&quot;UE APN&quot; /&gt;
&lt;img src=&quot;/images/ue_apn_setting.png&quot; alt=&quot;UE APN Setting&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Only two fields need to be filled, the first &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;name&lt;/code&gt; can be anything you like; the second &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;APN&lt;/code&gt; needs to be the same with settings in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;epc.conf&lt;/code&gt;, &lt;strong&gt;srsapn&lt;/strong&gt; by default.&lt;/p&gt;

&lt;p&gt;Now, you can surf the Internet by the custom built LTE network, just like Wi-Fi!&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Verizon&lt;/code&gt; service provider name(SPN) value is set in the USIM card.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ue_lock_screen.png&quot; alt=&quot;UE Lock Screen&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Speed test with &lt;a href=&quot;https://play.google.com/store/apps/details?id=com.netflix.Speedtest&quot;&gt;FAST Speed Test&lt;/a&gt; from Netflix.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/ue_lte_speed.png&quot; alt=&quot;Speed Test&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;reference&quot;&gt;Reference&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/srsLTE/srsLTE&quot;&gt;https://github.com/srsLTE/srsLTE&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://sourceforge.net/p/openlte/wiki/Programming%20you%20own%20USIM%20card/&quot;&gt;https://sourceforge.net/p/openlte/wiki/Programming%20you%20own%20USIM%20card/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://blog.csdn.net/u013429928/article/details/75319585&quot;&gt;https://blog.csdn.net/u013429928/article/details/75319585&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">Build a LTE Network with srsLTE and Program Your Own USIM Card</summary></entry><entry><title type="html">Build a GSM Network with OpenBSC OsmoBTS OsmoTRX and USRP B210 on a Single PC</title><link href="https://cyberloginit.com//2018/04/27/build-a-gsm-network-with-openbsc-osmobts-osmotrx-and-usrp-b210-on-a-single-pc.html" rel="alternate" type="text/html" title="Build a GSM Network with OpenBSC OsmoBTS OsmoTRX and USRP B210 on a Single PC" /><published>2018-04-27T00:00:00+00:00</published><updated>2018-04-27T00:00:00+00:00</updated><id>https://cyberloginit.com//2018/04/27/build-a-gsm-network-with-openbsc-osmobts-osmotrx-and-usrp-b210-on-a-single-pc</id><content type="html" xml:base="https://cyberloginit.com//2018/04/27/build-a-gsm-network-with-openbsc-osmobts-osmotrx-and-usrp-b210-on-a-single-pc.html">&lt;h1 id=&quot;build-a-gsm-network-with-openbsc-osmobts-osmotrx-and-usrp-b210-on-a-single-pc&quot;&gt;Build a GSM Network with OpenBSC OsmoBTS OsmoTRX and USRP B210 on a Single PC&lt;/h1&gt;

&lt;p&gt;This document assumes that you have basic knowledge of the GSM network architecture(MSC, BTS, Abis, Um, etc.), Linux terminal and USRP UHD driver.&lt;/p&gt;

&lt;h2 id=&quot;environment&quot;&gt;Environment&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Intel Core i5-6500 CPU, 8 GB RAM, 64 GB HDD, Ethernet Connection, USB 3.0 Port&lt;/li&gt;
  &lt;li&gt;Ubuntu 16.04.4 Desktop 64-bit&lt;/li&gt;
  &lt;li&gt;USRP B210, Two GSM Antennas&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;structure&quot;&gt;Structure&lt;/h2&gt;
&lt;h3 id=&quot;gsm-network&quot;&gt;GSM Network&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://upload.wikimedia.org/wikipedia/commons/d/d1/Gsm_structures.svg&quot; alt=&quot;GSM Structure&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As for our GSM network, USRP B210, OsmoTRX and OsmoBTS consist the BTS(Base Transceiver Station),&lt;/p&gt;

&lt;p&gt;OpenBSC running as OsmoNITB (Network In The Box) implements a minimal subset of the BSC, MSC, SMSC and HLR.&lt;/p&gt;

&lt;h3 id=&quot;osmotrx&quot;&gt;OsmoTRX&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;a href=&quot;https://osmocom.org/projects/osmotrx/wiki/OsmoTRX&quot;&gt;OsmoTRX&lt;/a&gt; is a software-defined radio transceiver that implements the Layer 1 physical layer of a BTS.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;/images/OsmoTRX.png&quot; alt=&quot;OsmoTRX&quot; /&gt;&lt;/p&gt;

&lt;p&gt;It is the bridge between the RF hardware(USRP B210 in our case) and the OsmoBTS.&lt;/p&gt;

&lt;h3 id=&quot;osmobts&quot;&gt;OsmoBTS&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;a href=&quot;https://osmocom.org/projects/osmobts/wiki/Wiki&quot;&gt;OsmoBTS&lt;/a&gt; is a software implementation of a GSM BTS.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;/images/OsmoBTS.png&quot; alt=&quot;OsmoBTS&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;OsmoBTS is modular and has support for multiple back-ends.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;A back-end talks to a specific L1/PHY implementation of the respective BTS hardware.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In our case, OsmoBTS(osmo-bts-trx) talks to the OsmoTRX radio transceiver running on USRP B210.&lt;/p&gt;

&lt;h3 id=&quot;openbsc&quot;&gt;OpenBSC&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;&lt;a href=&quot;https://osmocom.org/projects/openbsc/wiki/OpenBSC&quot;&gt;OpenBSC&lt;/a&gt; started as a BSC (Base Station Controller) side implementation of the A-bis protocol,&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;It can run either as OsmoBSC, exposing an A interface towards an external MSC,&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;or as OsmoNITB (Network In The Box), whert implements a minimal subset of the BSC, MSC, SMSC and HLR.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;img src=&quot;/images/OpenBSC.png&quot; alt=&quot;OpenBSC&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As our GSM network runs on a single PC, OpenBSC runs here as OsmoNITB.&lt;/p&gt;

&lt;p&gt;It talks to OsmoBTS through Abis/IP.&lt;/p&gt;

&lt;h3 id=&quot;usrp-b210&quot;&gt;USRP B210&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://www.ettus.com/product/details/UB210-KIT&quot;&gt;USRP B210&lt;/a&gt; is a SDR(Software Define Radio) kit from Ettus.&lt;/p&gt;

&lt;p&gt;It transforms the digital signal on our computer into real world radio signal.&lt;/p&gt;

&lt;h2 id=&quot;installation&quot;&gt;Installation&lt;/h2&gt;
&lt;p&gt;Osmocom recommands that you should use your distribution’s package management system for installing stuff.&lt;/p&gt;

&lt;p&gt;As we will tinker with the source code later, so OpenBSC is built with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;make&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;As for OsmoBTS and OsmoTRX, you should install them from the Osmocom repository.&lt;/p&gt;

&lt;p&gt;Will come to that later.&lt;/p&gt;

&lt;p&gt;Set up our working directory as &lt;strong&gt;non-root&lt;/strong&gt; user&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mkdir ~/Projects
cd ~/Projects
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;openbsc-1&quot;&gt;OpenBSC&lt;/h3&gt;
&lt;p&gt;First install these dependencies:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo apt install libdbi-dev libdbd-sqlite3 libortp-dev build-essential libtool autoconf autoconf-archive automake git-core pkg-config libtalloc-dev libpcsclite-dev libpcap-dev
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then, build these projects bellow from source, following the &lt;a href=&quot;https://osmocom.org/projects/cellular-infrastructure/wiki/Build_from_Source&quot;&gt;Build from Source&lt;/a&gt; guide.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;libosmocore&lt;/li&gt;
  &lt;li&gt;libosmo-abis&lt;/li&gt;
  &lt;li&gt;libosmo-netif&lt;/li&gt;
  &lt;li&gt;openbsc&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For each project&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git clone git://git.osmocom.org/[project name]
cd [project name]
autoreconf -fi
./configure
make
make check
sudo make install
sudo ldconfig -i
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;In case of any missing dependency, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;./configure&lt;/code&gt; will tell you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For openbsc, you have to run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd openbsc/openbsc&lt;/code&gt; instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cd openbsc&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;osmobts-1&quot;&gt;OsmoBTS&lt;/h3&gt;
&lt;p&gt;As I have said earlier, installing from the Osmocom repository is preferred if you have no special excuse.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo su
wget http://download.opensuse.org/repositories/network:/osmocom:/latest/xUbuntu_16.04/Release.key 
apt-key add Release.key
rm Release.key
echo &quot;deb http://download.opensuse.org/repositories/network:/osmocom:/latest/xUbuntu_16.04/ ./&quot; &amp;gt; /etc/apt/sources.list.d/osmocom-latest.list
exit
sudo apt-get update
sudo apt-get install osmo-bts-trx
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If you should build it from source, make sure adding &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--enable-trx&lt;/code&gt; for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;./configure&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The other building process are the same with the above.&lt;/p&gt;

&lt;h3 id=&quot;osmotrx--uhd&quot;&gt;OsmoTRX &amp;amp; UHD&lt;/h3&gt;
&lt;p&gt;I had no luck building OsmoTRX from source, neither with UHD from Ettus PPA, nor UHD built from source.&lt;/p&gt;

&lt;p&gt;Past experiences tell me that the installation of UHD is very tricky.&lt;/p&gt;

&lt;p&gt;At last, I just install UHD and OsmoTRX from the Ubuntu repository.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo apt-get install osmo-trx libuhd-dev uhd-host
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;configuration&quot;&gt;Configuration&lt;/h2&gt;
&lt;h3 id=&quot;openbsc-2&quot;&gt;OpenBSC&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;Almost each Osmocom program has the configuration examples. Just look for ‘doc/examples/’.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you have built OpenBSC from source&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mkdir ~/.osmocom/
cp ~/Projects/openbsc/openbsc/doc/examples/osmo-nitb/sysmobts/openbsc.cfg  ~/.osmocom/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;No need to change the openbsc.cfg file here.&lt;/p&gt;

&lt;h3 id=&quot;osmobts-2&quot;&gt;OsmoBTS&lt;/h3&gt;
&lt;p&gt;If you have built OsmoBTS from source&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cp ~/Projects/osmo-bts/doc/examples/calypso/osmo-bts.cfg ~/.osmocom/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Delete &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;osmotrx legacy-setbsic&lt;/code&gt; from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;phy 0&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;osmotrx-1&quot;&gt;OsmoTRX&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;OsmoTRX can be configured with a variety of options on the command line. In most cases, the default settings will suffice.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;running&quot;&gt;Running&lt;/h2&gt;
&lt;p&gt;Open a shell and start OpenBSC&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo osmo-nitb -c ~/.osmocom/openbsc.cfg
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Open a shell and start OsmoBTS&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo osmo-bts-trx -c ~/.osmocom/osmo-bts.cfg
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Open a shell and start OsmoTRX&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo osmo-trx
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Search ‘Available networks’ from your phone, and you should seen &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Test PLMN 1-1 2G&lt;/code&gt; among local networks.&lt;/p&gt;

&lt;h2 id=&quot;reference&quot;&gt;Reference&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/samatt/SDR-101/blob/master/running_osmobts_with_usrp1_ubuntu_12.04.md&quot;&gt;https://github.com/samatt/SDR-101/blob/master/running_osmobts_with_usrp1_ubuntu_12.04.md&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://osmocom.org/projects/openbsc/wiki/OpenBSC&quot;&gt;https://osmocom.org/projects/openbsc/wiki/OpenBSC&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://osmocom.org/projects/openbsc/wiki/Building_OpenBSC&quot;&gt;https://osmocom.org/projects/openbsc/wiki/Building_OpenBSC&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://osmocom.org/projects/cellular-infrastructure/wiki/Build_from_Source&quot;&gt;https://osmocom.org/projects/cellular-infrastructure/wiki/Build_from_Source&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://osmocom.org/projects/osmobts/wiki/Wiki&quot;&gt;https://osmocom.org/projects/osmobts/wiki/Wiki&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://cn0xroot.com/2017/04/11/getting-started-with-3g-ip-access-nano3gopenbscosmocom-bb-part-1/&quot;&gt;https://cn0xroot.com/2017/04/11/getting-started-with-3g-ip-access-nano3gopenbscosmocom-bb-part-1/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://osmocom.org/projects/osmotrx/wiki/OsmoTRX&quot;&gt;https://osmocom.org/projects/osmotrx/wiki/OsmoTRX&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://osmocom.org/projects/baseband/wiki/CalypsoBTS&quot;&gt;https://osmocom.org/projects/baseband/wiki/CalypsoBTS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">Build a GSM Network with OpenBSC OsmoBTS OsmoTRX and USRP B210 on a Single PC</summary></entry><entry><title type="html">Visual Studio Code Tweaks on Windows 10</title><link href="https://cyberloginit.com//2018/04/08/visual-studio-code-tweaks-on-window-10.html" rel="alternate" type="text/html" title="Visual Studio Code Tweaks on Windows 10" /><published>2018-04-08T00:00:00+00:00</published><updated>2018-04-08T00:00:00+00:00</updated><id>https://cyberloginit.com//2018/04/08/visual-studio-code-tweaks-on-window-10</id><content type="html" xml:base="https://cyberloginit.com//2018/04/08/visual-studio-code-tweaks-on-window-10.html">&lt;h1 id=&quot;visual-studio-code-tweaks-on-windows-10&quot;&gt;Visual Studio Code Tweaks on Windows 10&lt;/h1&gt;

&lt;h2 id=&quot;integrated-terminal&quot;&gt;Integrated Terminal&lt;/h2&gt;
&lt;h3 id=&quot;set-bash-on-windows-as-default-terminal-environment&quot;&gt;Set Bash on Windows as default terminal environment.&lt;/h3&gt;
&lt;p&gt;To open the terminal, Use the Ctrl+` keyboard shortcut.&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;open the command palate with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl+Shift+P&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;open user setting&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;search &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bash&lt;/code&gt; to locate the setting item&lt;/li&gt;
  &lt;li&gt;add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;terminal.integrated.shell.windows&quot;: &quot;C:\\Windows\\System32\\bash.exe&quot;&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WORKSPACE SETTINGS&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;work-on-wsl&quot;&gt;Work on WSL&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;DON’T&lt;/strong&gt; modify any file of the WSL from Windows.&lt;/p&gt;

&lt;p&gt;However, we can work on files in our Windows file system from either within the WSL or without.
To sum it up:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;File Location&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Edit in Windows&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Edit in WSL&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Windows&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Yes&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;WSL&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;No&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Yes&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ol&gt;
  &lt;li&gt;Windows file system does &lt;strong&gt;not&lt;/strong&gt; include &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C:\Users\{username}\AppData\Local\Packages\{CanonicalGroupLimited.UbuntuonWindows}\LocalState\rootfs&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;WSL file system does &lt;strong&gt;not&lt;/strong&gt; include &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/mnt/[c, d, ...]&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To make your life easier, put your work directory in Windows file system (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/mnt/c/Users/{username}/Documents&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;This way, you can enjoy all the goodies from both Bash(Linux) and Windows, and edit your files from either environment.&lt;/p&gt;

&lt;h3 id=&quot;tricks&quot;&gt;Tricks&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;alias work='cd /mnt/c/Users/{username}/Documents/{work directory}'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;code .&lt;/code&gt; to open current directory in Visual Studio Code&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;wsl-git&quot;&gt;WSL Git&lt;/h2&gt;
&lt;p&gt;not supported yet:(&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/42606837/how-to-use-bash-on-windows-from-visual-studio-code-integrated-terminal&quot;&gt;https://stackoverflow.com/questions/42606837/how-to-use-bash-on-windows-from-visual-studio-code-integrated-terminal&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://code.visualstudio.com/docs/editor/integrated-terminal&quot;&gt;https://code.visualstudio.com/docs/editor/integrated-terminal&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/Microsoft/vscode/issues/29812&quot;&gt;https://github.com/Microsoft/vscode/issues/29812&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</content><author><name></name></author><summary type="html">Visual Studio Code Tweaks on Windows 10</summary></entry><entry><title type="html">Debrick WD MyCloud 3TB without Opening Case in Linux</title><link href="https://cyberloginit.com//2017/12/31/debrick-wd-mycloud-3tb-without-opening-case-in-linux.html" rel="alternate" type="text/html" title="Debrick WD MyCloud 3TB without Opening Case in Linux" /><published>2017-12-31T00:00:00+00:00</published><updated>2017-12-31T00:00:00+00:00</updated><id>https://cyberloginit.com//2017/12/31/debrick-wd-mycloud-3tb-without-opening-case-in-linux</id><content type="html" xml:base="https://cyberloginit.com//2017/12/31/debrick-wd-mycloud-3tb-without-opening-case-in-linux.html">&lt;h2 id=&quot;about&quot;&gt;About&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;created: 2015/05/16&lt;/li&gt;
  &lt;li&gt;edited: 2017/12/31&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;requirements&quot;&gt;Requirements&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;A router running OpenWrt;&lt;/li&gt;
  &lt;li&gt;Recovery software from &lt;a href=&quot;http://community.wd.com/t5/user/viewprofilepage/user-id/280916&quot;&gt;Fox_exe&lt;/a&gt;, download it &lt;a href=&quot;https://docs.google.com/file/d/0B_6OlQ_H0PxVRndzakJhRXZ3OHM/edit&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;steps&quot;&gt;Steps&lt;/h2&gt;
&lt;h3 id=&quot;first-setup-a-tftp-server-with-openwrt&quot;&gt;First, setup a TFTP server with OpenWrt&lt;/h3&gt;

&lt;p&gt;You need to make sure that dnsmasq has been installed on your router,&lt;/p&gt;

&lt;p&gt;then open up &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/config/dhcp&lt;/code&gt; and under the ‘dnsmasq’ section add the following lines (or if these lines already exist, adjust the values to match).&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;option enable_tftp '1'
option tftp_root '/var/tftp'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;create a folder on your OpenWrt router where the recovery system for debricking WD MyCloud will be stored&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mkdir /var/tftp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;ATTENTION!&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/var&lt;/code&gt; is a link to/tmp, which will be flushed after reboot. Then &lt;del&gt;it&lt;/del&gt; the missing folder will prevent dnsmasq form starting up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Make sure&lt;/strong&gt; you uncomment these options above beforing rebooting, or change the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tftp_root&lt;/code&gt; folder to somewhere else if your router have plenty of space left.&lt;/p&gt;

&lt;p&gt;Then, upload two files &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bootimage&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;start.sh&lt;/code&gt; in the downloaded root folder to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/var/tftp&lt;/code&gt;。
Restart dnsmasq&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;/etc/init.d/dnsmasq restart
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;to apply these changes.&lt;/p&gt;

&lt;h3 id=&quot;second-bring-yourwd-mycloud-back-alive&quot;&gt;Second, bring your WD MyCloud back alive!&lt;/h3&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Make sure that nmap is installed.&lt;/p&gt;

    &lt;p&gt;In your computer’s terminal&lt;/p&gt;
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo nping --dest-mac &amp;lt;Your WD MyCloud's MAC&amp;gt; -c 999 --icmp --icmp-type echo --icmp-code 0 --data-string WD-ICMP-BEACON 255.255.255.255
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Power on your WD MyCloud(Get its IP address in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/var/dhcp.leases&lt;/code&gt; if you have enabled dhcp of your router)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;telnet &amp;lt;Your WD MyCloud's IP&amp;gt;&lt;/code&gt; from your computer. 
 If everything went well, you should be able to see
```
Trying 192.168.1.2…
Connected to 192.168.1.2.
Escape character is ‘^]’.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;/ #
```&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Troubleshoot the system or install a new one.
 I prefer clean debian. You can get it from the first reference bellow.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;how-it-works&quot;&gt;How it works?&lt;/h2&gt;
&lt;p&gt;Well, basically “WD-ICMP-BEACON” is a backdoor, &lt;/p&gt;

&lt;p&gt;WD MyCloud will try to boot from a TFTP server if it receives the specific packet &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--data-string WD-ICMP-BEACON&lt;/code&gt; during startup.&lt;/p&gt;

&lt;h2 id=&quot;furthermore&quot;&gt;Furthermore&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;All you needs is a TFTP server, I choose OpenWrt  +dnsmasq for convenience;&lt;/li&gt;
  &lt;li&gt;You can actually use any TFTP image to do the trick, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bootimage&lt;/code&gt; used here has limited functions(I even have to use netcat to upload the system recover image);&lt;/li&gt;
  &lt;li&gt;As for debricking in Windows, just follow Fox_exe’s README.txt in the Recovery software folder.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;reference&quot;&gt;Reference&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://community.wd.com/t5/WD-My-Cloud/Clean-debian-and-OpenMediaVault-on-WDMyCloud/td-p/785505&quot;&gt;http://community.wd.com/t5/WD-My-Cloud/Clean-debian-and-OpenMediaVault-on-WDMyCloud/td-p/785505&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://stelfox.net/blog/2014/07/using-openwrts-dnsmasq-as-a-tftp-server/&quot;&gt;https://stelfox.net/blog/2014/07/using-openwrts-dnsmasq-as-a-tftp-server/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.nasyun.com/thread-24024-1-1.html&quot;&gt;http://www.nasyun.com/thread-24024-1-1.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">About created: 2015/05/16 edited: 2017/12/31</summary></entry><entry><title type="html">一加一代使用联通4G及高通固件详解</title><link href="https://cyberloginit.com//2017/12/31/oneplus-one-cyanogen-os-use-lte-on-china-unicom-and-qualcomm-firmware-explain.html" rel="alternate" type="text/html" title="一加一代使用联通4G及高通固件详解" /><published>2017-12-31T00:00:00+00:00</published><updated>2017-12-31T00:00:00+00:00</updated><id>https://cyberloginit.com//2017/12/31/oneplus-one-cyanogen-os-use-lte-on-china-unicom-and-qualcomm-firmware-explain</id><content type="html" xml:base="https://cyberloginit.com//2017/12/31/oneplus-one-cyanogen-os-use-lte-on-china-unicom-and-qualcomm-firmware-explain.html">&lt;h2 id=&quot;摘要&quot;&gt;摘要&lt;/h2&gt;
&lt;p&gt;使用fastboot刷Oxygen OS的固件，解决一加一手机刷Cyanogen OS后无法使用联通3G、4G网络的问题。&lt;/p&gt;

&lt;h2 id=&quot;环境&quot;&gt;环境&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Windows/Linux/macOS&lt;/li&gt;
  &lt;li&gt;fastboot &lt;a href=&quot;https://developer.android.com/studio/releases/platform-tools.html&quot;&gt;此处下载&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;前言&quot;&gt;前言&lt;/h2&gt;
&lt;p&gt;心血来潮买了张联通卡，满怀欣喜插入一加一（Cyanogen OS cm-13.1-ZNH2KAS1KN），网络一直是2G EDGE。想到因LTE牌照问题，一加一在国内不正式支持联通3G、4G。
官网说&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;WCDMA和 FDD-LTE两种网络制式需国际漫游状态时才能使用&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;但面向海外的Cyanogen OS居然也不支持，着实让人惊讶。&lt;/p&gt;

&lt;p&gt;先用中文搜索了一下这个问题，中文互联网社区有几个帖子试图解决这个问题，本方案的灵感也部分来源于此帖。&lt;/p&gt;

&lt;p&gt;&lt;del&gt;但此类帖子多流于教程，而非技术。本着看教程不如学原理的原则，我们需要从这些神秘兮兮的教程步骤里提取出隐藏的信息。&lt;/del&gt;&lt;/p&gt;

&lt;p&gt;既然Oxygen OS支持联通3G、4G，说明该ROM的固件（其实是基带）是支持的。&lt;/p&gt;

&lt;h2 id=&quot;过程&quot;&gt;过程&lt;/h2&gt;

&lt;h3 id=&quot;第一次尝试失败&quot;&gt;第一次尝试（失败）&lt;/h3&gt;
&lt;p&gt;本以为简单地刷个&lt;a href=&quot;https://forums.oneplus.net/threads/oxygenos-2-1-4-for-the-oneplus-one.425544/&quot;&gt;Oxygen OS 2.1.4&lt;/a&gt;的modem&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;fastboot flash modem NON-HLOS.bin
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;就能成功，结果开机后无法使用任何网络。&lt;/p&gt;

&lt;h3 id=&quot;第二次尝试失败&quot;&gt;第二次尝试（失败&lt;/h3&gt;
&lt;p&gt;同样只刷modem，这次受上述帖子影响，使用了Oxygen OS 1.0的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NON-HLOS.bin&lt;/code&gt;文件，刷完回到了Cyanogen OS 13，看了一下基带版本，居然是一样的。。。&lt;/p&gt;

&lt;h3 id=&quot;第三次尝试成功&quot;&gt;第三次尝试（成功）&lt;/h3&gt;
&lt;p&gt;刷&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cm-13.1-ZNH2KAS1KN-bacon-signed-fastboot-a03c8dbbd0.zip&lt;/code&gt;时需要在fastboot模式分别刷从LOGO到system的各个文件（所谓的把系统恢复成完全原生的方法），
那个压缩包中有个flash-radio.sh脚本，可以“一键”刷所有固件&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;fastboot flash aboot emmc_appsboot.mbn
fastboot flash LOGO logo.bin
fastboot flash rpm rpm.mbn
fastboot flash modem NON-HLOS.bin
fastbootflash sbl1 sbl1.mbn
fastboot flash dbi sdi.mbn
fastboot flash oppostanvbk static_nvbk.bin
fastboot flash tz tz.mbn
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;del&gt;不太理解其中的几个分区的功能，比如aboot，rpm，sbl1，dbi，oppostanvbk（暴露了一加的东家），但感觉这几个文件应该功能紧密相连（本文水平好像比自己鄙视的教程党高不到哪里去。。。），所以决定把这几个分区都刷了。&lt;/del&gt;~&lt;/p&gt;

&lt;p&gt;还是使用Oxygen OS 2.1.4的固件。当然，有这个脚本方便多了，真是“一键”刷机。&lt;/p&gt;

&lt;p&gt;重启后，忐忑不安的盯着开机界面，生怕刷成砖了，还好顺利进入系统，这时基带版本已经是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.4.0.1.c7-00013&quot;&lt;/code&gt;。&lt;/p&gt;

&lt;p&gt;Cyanogen OS 13和Oxygen OS 1.0都是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DI.3.0.c6-00241&lt;/code&gt;，看版本号，还是Oxygen OS 2.1.4的基带更新啊（难道CM和一加闹掰后Cyanogen OS也不给好好做了）。&lt;/p&gt;

&lt;p&gt;如此看来，固件（Firmware）还是用Oxygen OS以及对应的氢OS的最新版比较好，即使这版Oxygen OS只是个社区版。&lt;/p&gt;

&lt;h2 id=&quot;高通固件说明&quot;&gt;高通固件说明&lt;/h2&gt;
&lt;h3 id=&quot;aboot-emmc_appsbootmbn&quot;&gt;aboot emmc_appsboot.mbn&lt;/h3&gt;
&lt;p&gt;application processor(对应baseband processor) boot loader；&lt;/p&gt;

&lt;p&gt;emmc(embedded MMC)，Android手机常用的存储设备，当然各个固件也存储其中；&lt;/p&gt;

&lt;p&gt;mbn(Multi Boot Image)，使用&lt;a href=&quot;https://github.com/openpst/readmbn&quot;&gt;readmbn&lt;/a&gt;可查看文件内容&lt;/p&gt;

&lt;h3 id=&quot;logo-logobin&quot;&gt;LOGO logo.bin&lt;/h3&gt;
&lt;p&gt;没什么好说的，开机动画，其实是个压缩文件，网上有大量自定义教程。&lt;/p&gt;

&lt;h3 id=&quot;rpm-rpmmbn&quot;&gt;rpm rpm.mbn&lt;/h3&gt;
&lt;p&gt;Resource Power Manager，负责设备的电源管理等。&lt;/p&gt;

&lt;h3 id=&quot;modem-non-hlosbin&quot;&gt;modem NON-HLOS.bin&lt;/h3&gt;
&lt;p&gt;基带系统固件&lt;/p&gt;

&lt;p&gt;NON-HLOS(NON High Level OS)即基带处理器的系统，与HLOS(High Level OS) Android对应；&lt;/p&gt;

&lt;p&gt;里面包含GNSS(Global Navigation Satellite System)，如GPS，子系统的控制模块；&lt;/p&gt;

&lt;p&gt;还有mDSP(modem Digital Sigal Processor)等子系统的控制模块；&lt;/p&gt;

&lt;p&gt;网上有泄露的高通某些型号基带源码，可以&lt;a href=&quot;https://syshwid.blogspot.com/2016/10/build-qualcomm-modem-msm8626.html&quot;&gt;自己编译&lt;/a&gt;;&lt;/p&gt;

&lt;p&gt;参考&lt;a href=&quot;https://zhiwei.li/text/2015/08/16/%E4%BB%8E%E5%88%B7%E6%9C%BA%E5%8C%85%E6%88%96%E8%80%85%E5%B7%B2%E7%BB%8Froot%E7%9A%84%E6%89%8B%E6%9C%BA%E4%B8%AD%E6%8F%90%E5%8F%96%E5%9F%BA%E5%B8%A6%E5%9B%BA%E4%BB%B6/&quot;&gt;此文&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;NON-HLOS.bin 实际就是一个FAT16格式的磁盘映像
有两种方法取得&lt;/p&gt;
  &lt;ol&gt;
    &lt;li&gt;从刷机包中解压缩&lt;/li&gt;
    &lt;li&gt;从root的手机中获取
挂载镜像
      &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;su -
mkdir mountpoint
mount -o loop NON-HLOS.bin mountpoint
cp -r mountpoint modem
umount mountpoint
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;      &lt;/div&gt;
      &lt;p&gt;现在在modem目录下就有初步提取的底层驱动的文件了。&lt;/p&gt;
    &lt;/li&gt;
  &lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;使用&lt;a href=&quot;https://forum.xda-developers.com/general/general/revskills-pro-edition-v2-08-6-t3489697&quot;&gt;Revskills Pro&lt;/a&gt;可以把&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.b00&lt;/code&gt;格式的文件转换成elf文件。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;提取过程中，如果遇到空缺的文件，会报告错误。你可以创建一个大小为0的空文件，文件名就为那个丢失的文件。然后重试。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;最后你将得到一个类似于 modem.elf的文件，可以放入IDA Pro中分析。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;IDA Pro不能正确解析这种架构（QDSP6）的二进制文件，可以使用&lt;a href=&quot;https://github.com/gsmk/hexagon&quot;&gt;这个&lt;/a&gt;模块，也可以参考&lt;a href=&quot;https://github.com/programa-stic/hexag00n&quot;&gt;这里&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;sbl1-sbl1mbn&quot;&gt;sbl1 sbl1.mbn&lt;/h3&gt;
&lt;p&gt;Secondary Boot Loader；&lt;/p&gt;

&lt;p&gt;高通SoC(System on Chip)启动过程中有很多boot loader，一加一使用的MSM 8974AC把sbl1, sbl2, sbl3合并到了一个文件sbl1中。&lt;/p&gt;

&lt;h3 id=&quot;dbi-sdimbn&quot;&gt;dbi sdi.mbn&lt;/h3&gt;
&lt;p&gt;未知&lt;/p&gt;

&lt;h3 id=&quot;oppostanvbk-static_nvbkbin&quot;&gt;oppostanvbk static_nvbk.bin&lt;/h3&gt;
&lt;p&gt;网络参数设定&lt;/p&gt;

&lt;h3 id=&quot;tz-tzmbn&quot;&gt;tz tz.mbn&lt;/h3&gt;
&lt;p&gt;Trust Zone&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Arm TrustZone technology is a System on Chip (SoC) and CPU system-wide approach to security.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;TrustZone is hardware-based security built into SoCs by semiconductor chip designers who want to provide secure end points and a device root of trust.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;吐槽&quot;&gt;吐槽&lt;/h2&gt;
&lt;p&gt;上文用到的几个文件都是在一加的英文论坛找到的，固件几十兆而已，可以直接下载，无需注册，有些链接可能打不开，请自备梯子。
&lt;a href=&quot;https://forums.oneplus.net/threads/list-oneplus-one-firmwares-modems.421783/&quot;&gt;链接&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;联通4G的室内信号在我这里的确比移动好很多，前者基本全满，后者最好也只是一半。&lt;/p&gt;

&lt;p&gt;最后一定要吐槽一下国内论坛（至此您可以关掉这个页面，去享受联通4G的畅快了）&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;帖子里共享文件似乎很喜欢用百度云，百度这公司的产品能信吗？？？
 结果是没几天后链接就失效了，然后帖子下面一帮人求文件。。。&lt;/p&gt;

    &lt;p&gt;与此形成鲜明对比的是，国外（主要是英文）的类似论坛分享的文件很多过了几年还可以下载。&lt;/p&gt;

    &lt;p&gt;文件无法正常下载的后果是，教程的可用度会打很大折扣。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;好多不重要，也不大的文件，下载必须要注册，还要扣虚拟货币（说你呢，一加中文论坛，都什么年代了也不知道上HTTPS，看看你的国际版对手，全站HTTPS，对自己同胞就可以这样“不讲究”吗）。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;后记&quot;&gt;后记&lt;/h2&gt;
&lt;p&gt;第一版成文于2016年7月10日，文中吐槽相关的文字都是这版遗留的；&lt;/p&gt;

&lt;p&gt;第二版于2017年12月31日完成，揭开了高通SoC中诸多固件的神秘面纱，希望能为这个方向的研究者提供参考。&lt;/p&gt;

&lt;h2 id=&quot;参考&quot;&gt;参考&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://forums.oneplus.net/threads/list-oneplus-one-firmwares-modems.421783/&quot;&gt;https://forums.oneplus.net/threads/list-oneplus-one-firmwares-modems.421783/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://security.tencent.com/index.php/blog/msg/38&quot;&gt;https://security.tencent.com/index.php/blog/msg/38&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://zhiwei.li/text/2015/08/16/%E4%BB%8E%E5%88%B7%E6%9C%BA%E5%8C%85%E6%88%96%E8%80%85%E5%B7%B2%E7%BB%8Froot%E7%9A%84%E6%89%8B%E6%9C%BA%E4%B8%AD%E6%8F%90%E5%8F%96%E5%9F%BA%E5%B8%A6%E5%9B%BA%E4%BB%B6/&quot;&gt;https://zhiwei.li/text/2015/08/16/%E4%BB%8E%E5%88%B7%E6%9C%BA%E5%8C%85%E6%88%96%E8%80%85%E5%B7%B2%E7%BB%8Froot%E7%9A%84%E6%89%8B%E6%9C%BA%E4%B8%AD%E6%8F%90%E5%8F%96%E5%9F%BA%E5%B8%A6%E5%9B%BA%E4%BB%B6/&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.arm.com/products/security-on-arm/trustzone&quot;&gt;https://www.arm.com/products/security-on-arm/trustzone&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">摘要 使用fastboot刷Oxygen OS的固件，解决一加一手机刷Cyanogen OS后无法使用联通3G、4G网络的问题。</summary></entry></feed>