title: Python concatenate bytes to str
body: <p>Is is possible to concatenate bytes to str?</p>
  <pre><code>&gt;&gt;&gt; b = b'this is bytes'
  &gt;&gt;&gt; s = 'this is string'
  &gt;&gt;&gt; b + s
  Traceback (most recent call last):
    File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  TypeError: can't concat str to bytes
  &gt;&gt;&gt; 
  </code></pre>
  <p>It is not possible based on simple code above.</p>
  <p>The reason I'm asking this as I've seen a code where bytes has been concatenated to str?
  Here is the snipet of the code.</p>
  <pre><code>buf =  &quot;&quot;
  buf += &quot;\xdb\xd1\xd9\x74\x24\xf4\x5a\x2b\xc9\xbd\x0e\x55\xbd&quot;
  
  buffer = &quot;TRUN /.:/&quot; + &quot;A&quot; * 2003 + &quot;\xcd\x73\xa3\x77&quot; + &quot;\x90&quot; * 16 +  buf + &quot;C&quot; * (5060 - 2003 - 4 - 16 - len(buf))
  </code></pre>
  <p>You can see the full code here.</p>
  <p><a href="http://sh3llc0d3r.com/vulnserver-trun-command-buffer-overflow-exploit/" rel="nofollow noreferrer">http://sh3llc0d3r.com/vulnserver-trun-command-buffer-overflow-exploit/</a></p>