<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Thiago Macedo</title>
    <description>The latest articles on Forem by Thiago Macedo (@thiagofm).</description>
    <link>https://forem.com/thiagofm</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F265797%2Ffafc810b-1824-4506-9a39-66245e431705.JPG</url>
      <title>Forem: Thiago Macedo</title>
      <link>https://forem.com/thiagofm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/thiagofm"/>
    <language>en</language>
    <item>
      <title>SSL Pinning Exposed: Can the Web Save Us?</title>
      <dc:creator>Thiago Macedo</dc:creator>
      <pubDate>Sun, 21 Jan 2024 07:26:14 +0000</pubDate>
      <link>https://forem.com/thiagofm/ssl-pinning-exposed-can-the-web-save-us-3g82</link>
      <guid>https://forem.com/thiagofm/ssl-pinning-exposed-can-the-web-save-us-3g82</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Data security in mobile applications today depends on SSL pinning - and it has loopholes. Would it be possible to re-elect the web as safer? That's what I tried.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Sometime ago I &lt;a href="https://insights.guardsquare.com/ssl-pinning-explained"&gt;received a video&lt;/a&gt; that exposed weaknesses in SSL Pinning, the technology that ensures data communication in mobile applications. I had already worked on apps that use the technique - as well as having tried to break it before - so I thought it would be interesting to investigate.&lt;/p&gt;

&lt;p&gt;This &lt;a href="https://medium.com/@zhangqichuan/explain-ssl-pinning-with-simple-codes-eaee95b70507"&gt;data transmission security&lt;/a&gt; solution consists of establishing an SSL certificate together with the application build - for exclusive client-server communication through this key. As the build &lt;em&gt;embeds&lt;/em&gt; its own set of certificates, it protects itself from attacks on the &lt;em&gt;Certificate Store&lt;/em&gt; of the client's operating system, for example.&lt;/p&gt;

&lt;p&gt;Along with its popularity, the technique has been receiving attention from cyber defense authorities as it has weaknesses that allow apps to be tampered with bad keys. Through reverse engineering, it is possible to tamper a build with malicious keys and thus expose the client to impersonalization attacks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Web or Mobile? The safe choice
&lt;/h2&gt;

&lt;p&gt;After investigating the structure of these attacks, I realized that the web environment had the potential to be more resilient to tampering.&lt;/p&gt;

&lt;p&gt;Mobile applications are delivered directly to the client host, thus being exposed to the fate of the OS and device itself. At the other end, let's say a PWA Web application, its release is restricted to the browser context only.&lt;/p&gt;

&lt;p&gt;However, to reach the level of security that pinning proposes, a web release would need to contain at least two characteristics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;allowing the validation of original certificates;&lt;/li&gt;
&lt;li&gt;being resilient to the tampering of this information.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  SSL pinout: Authority is what counts
&lt;/h2&gt;

&lt;p&gt;I started the research with SSL Pinning. Conceptually, the idea is great: linking the frontend application to an exclusive set of certificates. But in practice, the approach creates problems as it exposes the certificates in the build, being subject to reverse engineering, and tampering, among others.&lt;/p&gt;

&lt;p&gt;Would there then be something similar in the browser? The answer is yes.&lt;/p&gt;

&lt;p&gt;In 2013, Google created &lt;a href="https://transparencyreport.google.com/https/certificates"&gt;a mechanism to help&lt;/a&gt; defend against attacks on the CA Store, called &lt;strong&gt;Certificate Transparency&lt;/strong&gt;. This is an internet standard in which digital authorities must publish public logs with all their issued certificates. This way, the client browser itself can decide whether a given domain has such a certificate, or whether it is fake.&lt;/p&gt;

&lt;p&gt;The approach has been gaining ground and since 2018 &lt;strong&gt;Google Chrome&lt;/strong&gt; has required that all certificates be available in a public log.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tamparing the application
&lt;/h2&gt;

&lt;p&gt;The pinned release can have its certificates patched if the client is exposed. The attacker can also change the frontend to call his domains and impersonate the whole API.&lt;/p&gt;

&lt;p&gt;As the web application does not pin the certificate - but rather authenticates it in the global transparency repository - there is no risk of certificate tampering.&lt;/p&gt;

&lt;p&gt;Unfortunately browsers, as a rule, &lt;a href="https://www.theverge.com/2013/10/11/4828958/chrome-history-cache-security-flaw"&gt;do not encrypt the cache&lt;/a&gt;, leaving it up to the user to protect themselves with storage encryption solutions. Therefore the attacker, in possession of the host, can manipulate the application cache and its version as well. However, the multiple security layers on the browser (like CORS) will likely make the tampering impractical.&lt;/p&gt;

&lt;h2&gt;
  
  
  Obscurantist solution: the hack against reverse engineering
&lt;/h2&gt;

&lt;p&gt;A simple and reasonably effective solution is to employ techniques to make it difficult to manipulate compromising information: in this case, URLs in javascript builds or SSL keys embedded in the mobile release.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Obfuscation&lt;/strong&gt; is the means of &lt;a href="https://en.wikipedia.org/wiki/Obfuscation_(software)"&gt;deliberately creating code that is difficult to read&lt;/a&gt; and reverse engineering. There are automatic solutions, but manual care is necessary if the intention is to protect yourself from more skilled attackers.&lt;/p&gt;

&lt;p&gt;Another technology being developed is the in-memory validation of code hashes. This approach, promising against tampering, consists of validating at runtime whether the method has been modified, preventing the program from continuing in the event of tampering.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connecting the dots
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Certificate Transparency&lt;/em&gt; seems to me to be an important advance and could be incorporated into other environments in the future.&lt;/p&gt;

&lt;p&gt;Unfortunately, mobile application frameworks do not evolve with the same cohesion and timing as the W3C or Google Chrome, leaving the promising solution resident of just a few use cases.&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>webdev</category>
      <category>mobile</category>
    </item>
    <item>
      <title>How to recover LTC sent by mistake to a BTC wallet</title>
      <dc:creator>Thiago Macedo</dc:creator>
      <pubDate>Sun, 21 Jan 2024 06:13:42 +0000</pubDate>
      <link>https://forem.com/thiagofm/how-to-recover-ltc-sent-by-mistake-to-a-btc-wallet-5h52</link>
      <guid>https://forem.com/thiagofm/how-to-recover-ltc-sent-by-mistake-to-a-btc-wallet-5h52</guid>
      <description>&lt;p&gt;Bitcoin and Litecoin are technically very similar cryptocurrencies, with Litecoin being a fork of Bitcoin created in 2011.&lt;/p&gt;

&lt;p&gt;Their wallet addresses are also technically the same. If you have created a BTC wallet and have its key, you are the owner of the same LTC address and can open it with your existing BTC keys.&lt;/p&gt;

&lt;p&gt;Given the average user experience in crypto-currency interfaces is improving yet due to their inherent complexity, one can accidentally transfer an X amount of LTC to a BTC address. Well, at least I did.&lt;/p&gt;

&lt;p&gt;This post will describe how I have discovered that my LTC tokens could be recovered even if I had transferred them to the wrong address - in this case a known BTC address.&lt;/p&gt;

&lt;h2&gt;
  
  
  Networks do not communicate
&lt;/h2&gt;

&lt;p&gt;The fact is: that sending LTC to a BTC address does not make the coins never leave the original network. Litecoins sent by mistake are always and only in the LTC network. In this case, as we used a Bitcoin address, the transfer was validated because it is the same format and this address is also valid on the LTC network.&lt;/p&gt;

&lt;p&gt;So where is the LTC? On the Litecoin network, at the address provided. And how to recover litecoins? If the person has control of the BTC wallet, they can recover the tokens.&lt;/p&gt;

&lt;h2&gt;
  
  
  The wallets are similar
&lt;/h2&gt;

&lt;p&gt;A Bitcoin wallet is nothing more than private keys (the keys that are used to sign a transaction) and recovery seeds. Litecoin works exactly the same, including the multisig wallet.&lt;/p&gt;

&lt;p&gt;Therefore, the wallet recovery procedure starts in the Bitcoin wallet. And you will learn about the blueprint of the operation below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wallets contain keys, not coins
&lt;/h2&gt;

&lt;p&gt;To recap: we send LTC to a “BTC” address. We have already discussed that the coins did not end up on the BTC network, however, the destination address is inviolable and we cannot undo the transaction.&lt;/p&gt;

&lt;p&gt;The solution here, paradoxically, lies in the &lt;strong&gt;BTC wallet&lt;/strong&gt;. Once we have this wallet with the destination address, we can retrieve the same address on the LTC network.&lt;/p&gt;

&lt;p&gt;In practice, as the networks are similar, a BTC address has parity in the LTC network, and we can take control of both networks with the Private Key or recovery seeds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recovering the wallet on the LTC network
&lt;/h2&gt;

&lt;p&gt;To take control of the address on the LTC network we need the private keys of the BTC wallet. Each wallet has a procedure, but there are basically three possibilities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The wallet allows you to export private keys;&lt;/li&gt;
&lt;li&gt;The wallet is non-encrypted and you can access the private key in the wallet files;&lt;/li&gt;
&lt;li&gt;The wallet is encrypted and we will need to recreate this wallet.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Look for the first two options and if you have access to the private key, skip the next step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decrypting a crypto wallet
&lt;/h2&gt;

&lt;p&gt;If the wallet is encrypted you can still recover it. We can recreate it without encryption. Of course, for this, you need to have the &lt;strong&gt;seed phrase&lt;/strong&gt;. Recovery keys must always be stored, as they are the only way to open the black box of a crypto wallet.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a BTC wallet;&lt;/li&gt;
&lt;li&gt;The new wallet must be a redemption from the seed phrase;&lt;/li&gt;
&lt;li&gt;The new wallet must be &lt;strong&gt;non-encrypted&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With the wallet decrypted, we can open the wallet file and access the private keys — which takes us to the next step. It would also be possible to generate the private-key with the seed phrase and the &lt;code&gt;https://iancoleman.io/bip39/&lt;/code&gt; tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  Taking control of LTC address with BTC private keys
&lt;/h2&gt;

&lt;p&gt;Once you have the &lt;strong&gt;private keys&lt;/strong&gt; for the LTC address that received the tokens, you must start creating the LTC wallet using the private keys.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create an LTC wallet;&lt;/li&gt;
&lt;li&gt;The new wallet must have the same signers number (if it is multisig);&lt;/li&gt;
&lt;li&gt;The new wallet must be a &lt;strong&gt;restoration&lt;/strong&gt; from the private keys.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The LTC wallets that I recommend for the process are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multisig address: core wallet&lt;/li&gt;
&lt;li&gt;segwit address: electrum wallet&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you have the wallet, just redirect the coins to a definitive LTC address. But if you have sent the coins to an address you don't have the keys you won't be able to recover them unless you know the owners.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>cryptocurrency</category>
    </item>
    <item>
      <title>Instrumentation for Laravel: visualize operational data and performance metrics</title>
      <dc:creator>Thiago Macedo</dc:creator>
      <pubDate>Thu, 07 Nov 2019 00:32:33 +0000</pubDate>
      <link>https://forem.com/thiagofm/instrumentation-for-laravel-the-job-queue-21ee</link>
      <guid>https://forem.com/thiagofm/instrumentation-for-laravel-the-job-queue-21ee</guid>
      <description>&lt;p&gt;Offloading tasks for background processing is such a great resource in software engineering. And a good job queue does the job of abstracting this complex setup in a safe and maintainable way.&lt;/p&gt;

&lt;p&gt;But as the number of jobs and data grows around the queue, we might wonder how much information we have about what is going on in the queue workers.&lt;/p&gt;

&lt;h3&gt;
  
  
  What instrumentation can answer
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--le7ZgqtK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/as1S99xl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--le7ZgqtK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/as1S99xl.png" alt="Huge job went down" width="640" height="162"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How many jobs ran last hour?&lt;/li&gt;
&lt;li&gt;What were the lengthiest tasks during that period of time?&lt;/li&gt;
&lt;li&gt;When did that job stop processing?&lt;/li&gt;
&lt;li&gt;What's the job run rate (how many per hour) and what's its average, max and minimum run times?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those questions will introduce themselves especially during performance incidents, system malfunctions, data loss, etc - so imagine how useful it is to have an informed dataset about the system health.&lt;/p&gt;

&lt;h3&gt;
  
  
  Horizon: mileage may vary
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jmLWS8gE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/KO6Hp2y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jmLWS8gE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/KO6Hp2y.png" alt="Horizon dashboard has a good interface" width="800" height="219"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the Laravel Queue there is the good &lt;a href="https://laravel.com/docs/master/horizon"&gt;Horizon Dashboard&lt;/a&gt;, which is free and readily integrates to redis queues. But if you need customized dashboards or to smash data in order to answers more questions then custom instrumentation comes handy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Determining what to instrument
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3i-Lx_fy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/YXLClK1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3i-Lx_fy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/YXLClK1.png" alt="Exeptions handled historigram" width="800" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For &lt;strong&gt;in-house instrumentation&lt;/strong&gt; where we consume the data ourselves I've been targeting to gather initially:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;name of the procedure&lt;/strong&gt; (the Job class name in this case)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;time spent processing&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;procedure params&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;caught exception description&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is a tendency to log out as much information as possible. For optimal instrumentation, don't do that. Include in the instrumentation payload only what's most relevant for the system operation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ingestion and data analysis
&lt;/h3&gt;

&lt;p&gt;Instrumentation data will be really useful only with &lt;em&gt;log ingestion and visualization tools&lt;/em&gt;. There are many projects out there in the market, such as the open-source Elastic Stack (logstash + kibana) and the paid service LogDNA.&lt;/p&gt;

&lt;h3&gt;
  
  
  Laravel Queue Instrumentation: a implementation
&lt;/h3&gt;

&lt;p&gt;Over the past year, I've solved lots of performance and data loss situations with a similar approach. Above I'm sharing a gist with a sample Laravel Queue instrumentation.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;How about your experience, have you ever instrumented system runtime? What tools and process do your team makes use?&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>performance</category>
      <category>devops</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
