<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by David Schiff on Medium]]></title>
        <description><![CDATA[Stories by David Schiff on Medium]]></description>
        <link>https://medium.com/@davidschiff_35251?source=rss-237e2d2315e3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*w3pbh-ufocf9Tp5jnVjgjQ.jpeg</url>
            <title>Stories by David Schiff on Medium</title>
            <link>https://medium.com/@davidschiff_35251?source=rss-237e2d2315e3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 20:00:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@davidschiff_35251/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Representation Engineering: Explained — Part I]]></title>
            <link>https://pub.towardsai.net/representation-engineering-explained-part-i-75b7e57212b1?source=rss-237e2d2315e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/75b7e57212b1</guid>
            <category><![CDATA[alignment]]></category>
            <category><![CDATA[aritificial-intelligence]]></category>
            <category><![CDATA[llm-applications]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[llm-evaluation]]></category>
            <dc:creator><![CDATA[David Schiff]]></dc:creator>
            <pubDate>Sun, 19 May 2024 12:44:14 GMT</pubDate>
            <atom:updated>2024-05-20T13:03:44.044Z</atom:updated>
            <content:encoded><![CDATA[<h3>Representation Engineering: Explained In Depth</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2Tvwo_HxdqAPji2-" /></figure><p>What is representation engineering? It’s a simple top down approach partially inspired by neuro/cognitive science in order to gain some control of a model. What type of control? Well, pretty much anything so it seems. In this story we’ll learn concept reading and control as discussed in the paper <a href="https://arxiv.org/abs/2310.01405">Representation Engineering: A Top-Down Approach to AI Transparency.</a> Concept reading and control is essentially knowing or controlling how much “honesty” or “anger” or “fear” is in a model’s response.</p><p>We can recall how transformers work, each transformer decoder block’s output is a matrix with as many rows as the length of the sequence and as many columns as the embedding dimensions. These column are called the context vectors. Each vector now represents the token and how its related to other tokens in the sequence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*Yd5JtrANYsGEnV3A-eSuHQ.png" /></figure><p>These vectors hold a lot of important information in them and it’s important that you understand what I’m talking about when I say context vectors.</p><p>Now, in Representation Engineering, the main idea is that we have many prompts which we can use to “scan” the LLM’s “brain”. This means that we want to see what type of neural activity is related to “honesty” or “brutality”.</p><p>How do we do this? We use different stimuli that have negative and positive examples of the “concept” such as:</p><pre>&quot;USER: Pretend you&#39;re an honest person making statements about the world. <br> ASSISTANT: The moon orbits around the Earth.&quot;<br><br>&quot;USER: Pretend you&#39;re an untruthful person making statements about the world. <br> ASSISTANT: The Earth orbits around the moon.&quot;</pre><p>We have many such negative and positive pairs of a certain concept. These pairs help us understand the exact activity related to honesty and dishonesty. It’s important to note that these samples are labeled. So we use a kind of supervised method to understand our model’s internal activity.</p><p>We read the activity from each <strong>last </strong>token of each sample. This is because the last token can attend to the full context of the sentence, it contains a rich representation of the sentence itself. The last token representation is present in every transformer decoder block and different layers have different “meanings” that correlate to those activations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*s3CZPPjpMHqBd-NNcaFdyA.png" /></figure><p>Now we simply run through our dataset of positive and negative samples and calculate the differences of each pair of samples (in the paper they say they use random pairings — not necessarily positive and negative pairs but also positive and positive). So now we have two vectors v1, and v2 for each pair and we have the difference between them — vector d = (v1-v2). We also have the labels of each sample (or stimuli). Now, using this concept, we can create a dataset of different vectors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*zmI5sC7eeaQWwy42fO48BQ.png" /><figcaption>Intuition for why PCA over the vector differences gives the direction of the “concept”</figcaption></figure><p>This dataset is very important because we can discover the “direction” of the activity that is most correlated with honesty using computational methods. One such method is PCA (Principal Component Analysis). Recall that PCA discovers the vectors that correspond to the maximal variance in the data. Consequently, the vector with the maximal variance is the vector along which the concepts vary the most! Pairs that had a maximal difference in the concept (say, honesty, for example) will vary greatly along the “direction” of honesty, and pairs that had a low difference in the concept will be quite around the zero vector, giving us exactly what we need when we extract the first principal component!</p><p>Finally, we can obtain the direction of the vector that corresponds with honesty by projecting our activity vectors onto the principal component vector. Then, we can check if our activity vector is negative or positive relative to our direction vector. This is simply done by getting the scalar, which is the result of our projection.</p><p>In the example below, we have a few activity vectors, each one given from an individual sample (matrix A). It’s important to note that these activity vectors come from a specific layer only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*picdCSbcVh13gHepFzI4_A.png" /></figure><p>So by multiplying our activity vectors with the principal component (normalized) we get the sign of the activation. Now we just need to understand which sign (positive or negative) is correlated to the concept we want to control. We can do this by checking how many positive numbers we have as a result of the projection that have the positive label of the concept (e.g honesty) and how many negative numbers we have with the concept. We’ll pick the sign that is mostly correlated with the positive label.</p><p>Now that we’ve trained our “concept classifier” we can “read” the mind of the model by checking the sign of it’s activity model. We can tell if the model is lying to us pretty easily, for example.</p><p>We can call this vector that we have extracted that points to the direction of our concept as the “reading vector”. We can now use this reading vector to control the models activity. Specifically, we’ll focus on how we can make the model more honest just like the example above.</p><p>How can we control our model? Well, we have a few methods that are described in the paper each one of them helps us guide the model in a certain way to generate relevant tokens.</p><ol><li><strong>LoRRA</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*TuI-AgGYI2UiYcjxysL7nw.png" /></figure><p>LoRRA is the first method in the paper to control the model. We can basically fine-tune our model by using low-rank adaptation (LoRA) to minimize the loss here. The loss is defined by the Euclidean distance between the target representations and the current model representations. The target representation is the transformed representation after getting the contrast vectors and adding them to the current representation plus some reading vectors.</p><p>Let’s break it down:</p><p>Contrast Vector — A vector that represents the difference in representation between a positive sample and a negative sample, for example, telling the AI to respond honestly about something or not. Just like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PvyEZPUTAchp5meQmibW-w.png" /></figure><p>These contrast vectors help tell the difference “in essence” between the two examples. One example is honesty, and the other one is not. We could use this to guide our model to be more honest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/0*eo1uEYiIsCUVa7_f.png" /></figure><p>This is our target representation per a certain layer in the model, which is the contrast vector and reading vector (which is optional) added to the current model representation in a specific layer.</p><p>Finally we can calculate the difference between our target representations and our current representations and add them to the loss. Note that we are only calculating the loss on the model answer and for each token we generate we calculate the representation loss and minimize the error.</p><p>We will do the same for each sample in our dataset. After we fine tuned our model using this method we have a model fine tuned for a certain function such as being honest.</p><p><strong>2. Contrast &amp; Reading Vector Control</strong></p><p>Another method that we can use, which is really much simpler than LoRRA but is not as effective, is just using the contrast vector or reading vector in inference to guide the model in generating responses in the direction we want, such as honesty. This can be done by simply reading the activations in a certain layer, adding the relevant reading vector (the vector that pushes the model response in the relevant direction e.g. honesty) and propagating that output to the next layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/0*gkubwjJDFvQw27DO.png" /></figure><p>Similarly, this vector could be a contrast vector as mentioned above.</p><p>So, to summarize, in this post, I explored Representation Engineering, a top-down approach inspired by cognitive science to gain control over AI models. This technique uses various prompts to analyze a model’s internal neural activity related to specific concepts like honesty or anger. By understanding context vectors in transformer models, we can determine the neural activity associated with different concepts.</p><p>We create a dataset of positive and negative examples of a concept, analyze the last token’s activity in each sample, and calculate the differences between paired samples. Using Principal Component Analysis (PCA), we can discover the direction of the concept, helping to identify the activity vector most correlated with it.</p><p>I discussed two main methods for controlling the model’s behavior. The first, LoRRA (Low-Rank Adaptation), fine-tunes the model by minimizing the difference between target and current representations using contrast vectors. The second method, Contrast &amp; Reading Vector Control, is simpler but less effective, involving the use of contrast or reading vectors during inference to guide the model’s responses in the desired direction.</p><p>By employing these methods, we can create models that exhibit specific behaviors, such as increased honesty, providing a way to understand and control AI model outputs more transparently.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75b7e57212b1" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/representation-engineering-explained-part-i-75b7e57212b1">Representation Engineering: Explained — Part I</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LogBERT Explained In Depth: Part II]]></title>
            <link>https://pub.towardsai.net/logbert-explained-in-depth-part-ii-f659abde9ebf?source=rss-237e2d2315e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/f659abde9ebf</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[anomaly-detection]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[transformers]]></category>
            <dc:creator><![CDATA[David Schiff]]></dc:creator>
            <pubDate>Sun, 09 Oct 2022 12:34:21 GMT</pubDate>
            <atom:updated>2022-10-09T17:10:17.120Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dlr48jSdYoqT53AQ" /></figure><p>In the previous article, I covered the basics of the Attention mechanism, and in general, I covered the transformer block. In this part of the series, I would like to cover how LogBERT trains and how we can use it to detect anomalies in log sequences.</p><p>Let’s get into the nitty gritty little details of LogBERT.</p><p>In the paper (link: <a href="https://arxiv.org/pdf/2103.04475.pdf">https://arxiv.org/pdf/2103.04475.pdf</a>) a log sequence is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/1*jXdrO-64QrPME9wvOIm2hw.png" /></figure><p>Where S is a sequence of keys (words) in the log sequence. Notice how our log keys are marked with a superscript j to indicate the sequence they belong to and a subscript over k to indicate the index in the series of words.</p><p>As usual, when training a transformer, we want to add a token to mark the beginning of the sequence, and the token will be “DIST” as mentioned in the paper. Another special token we will be adding is the “MASK” token. The mask token will be used to cover up words in the sentence.</p><p>If you take a look at the last part, you will remember our running example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*mbDcu3RjdYBNfXp9qkK4Qg.png" /><figcaption>Preprocessing our log sequences</figcaption></figure><p>As you can see, our log sequence is preprocessed to contain the different special tokens.</p><p><strong>DIST </strong>— Start of sentence</p><p><strong>MASK </strong>— Covers up a key in the sequence</p><p><strong>EOS </strong>— End of a sentence (Although not mentioned in the paper, it is used in the code on GitHub.)</p><p>Before I clear everything up about the special tokens, I want to review the training phase of LogBERT.</p><p>Recall the different parts of the LogBERT architecture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*HaliEr8aYzoCsdKKw1-iPQ.png" /><figcaption>Attention using the Q, K, and V matrices</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*GRw4dIqy2RR4hX4__lq3KA.png" /><figcaption>MultiHead Attention concatenating the different Attention heads</figcaption></figure><p>The functions above are just the mathematical descriptions of MultiHead Attention:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/0*mYfZj0LLNmLLaWgd.png" /></figure><p>And finally, it all comes down to the transformer block’s mathematical description:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*Avt6n1Tc0hPHuhcSM5Menw.png" /></figure><p>Which is just this whole transformer block:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*xAeHDzjlt7cMdoeailMpog.png" /></figure><p>Beautiful, now we have it all tied together. Usually, transformers have multiple transformer layers, which means we can assign a general transformer function which would be just a sequence of transformer blocks. This is described in the paper as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/1*mFtm9H9ZRZD3bQlmwQwLuA.png" /></figure><p>Where <strong>h</strong> is the output of the Transformer function, this output should be essentially just a vector that encodes all the information about the log sequence defined as X.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*b3UA4to1M8feWYGAL2ROXg.png" /></figure><p>I think the image above sums it all up. Just the general LogBERT architecture. Notice how the output layer is the size of the vocabulary. As usual in classification cases, specifically in our case, we need to classify the word covered under the MASK token. This leads me to the loss function of the final LogBERT model.</p><p>As mentioned earlier, all log sequences are preprocessed to contain a masked word. The model will try to predict the word being masked. This is a self-supervised task that the model will have to complete. The loss function for this task is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*zwkwDzbrrrhWklAzTU0fqA.png" /></figure><p>Where <strong>y</strong> is the real word under the mask and <strong>y hat</strong> is the probability assigned for the real word under the mask. We can see that the loss is essentially a categorical cross-entropy loss function where the categories are actually words. Notice how the summation is over N and M. N being the number of log sequences and M being the total number of masks chosen in the sentence.</p><p>For each log sequence, we choose a random word to mask with a probability of 0.15. We actually choose multiple words to mask, and for each log, we calculate the total loss over the mask prediction in the sentence. The final loss is summed over each sequence and divided by the number of log sequences.</p><p>The other task (loss function) that LogBERT needs to minimize is the Volume Of The HyperSphere loss function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/1*0t0P_XTwZIbPwPcGAucNwg.png" /></figure><p>This loss function uses <strong>h —</strong> as mentioned above. h is the representation of the log sequence (specifically h-dist), and the goal of this loss function is to minimize the distance between the representations of each log and their center. The center is updated with each epoch and is calculated as the average overall log representation.</p><p>Finally, both loss functions are used to update the model weights. The final loss function is comprised of a weighted sum of both loss functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/206/1*Srvtb612dup4Fyhjir8N0A.png" /></figure><p>Now, how do we use LogBERT to find anomalous logs? As proposed in the paper, we go over a log sequence and calculate the predictions for each masked word. We define a hyperparameter <strong>g</strong> which is the top g most probable words that lie beyond the mask. If the actual word is not in the top g words, we count that word as an anomaly. Now, we define r, another hyperparameter, as our threshold for counting a log as anomalous or not. If there are more than r word anomalies, the log sequence is defined as an anomalous log.</p><p>I would like to propose another method to locate anomalous logs. Simply use the final loss function and define a threshold z for which if a log scores higher than z it is an anomalous log.</p><p>That’s it, I hope you enjoyed your read. I highly recommend reading up on the original paper and hopping over to GitHub to look at the code itself.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f659abde9ebf" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/logbert-explained-in-depth-part-ii-f659abde9ebf">LogBERT Explained In Depth: Part II</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LogBERT Explained In Depth: Part I]]></title>
            <link>https://pub.towardsai.net/logbert-explained-in-depth-part-i-771463d7beda?source=rss-237e2d2315e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/771463d7beda</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[anomaly-detection]]></category>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <category><![CDATA[logbert]]></category>
            <category><![CDATA[transformers]]></category>
            <dc:creator><![CDATA[David Schiff]]></dc:creator>
            <pubDate>Mon, 26 Sep 2022 16:02:20 GMT</pubDate>
            <atom:updated>2022-10-09T12:37:15.023Z</atom:updated>
            <content:encoded><![CDATA[<p>Link to original paper: <a href="https://arxiv.org/pdf/2103.04475.pdf">https://arxiv.org/pdf/2103.04475.pdf</a></p><p>One of the greatest frontiers in IT and system administration is dealing with application and system failures. Sometimes the reason for the failure is extremely difficult to find. When system technicians and application developers need to find the cause for the failure of their application, they usually read the log files generated by said system. The technician will then find the log relevant to the crash and will use this information to recover from the failure. The problem with this technique is that sometimes systems and applications generate hundreds of thousands of logs and even millions. The job of looking for the single log message that would have predicted the crash could take a very long time, and the task itself may be exhausting.</p><p>Over the years, many methods have been proposed for dealing with this task of finding the relevant log message. Many of these methods use ideas that come from the anomaly detection field. As we can assume a priori, the log that will predict the crash and can give an indication as to what caused it should itself be anomalous. This is because if it was not anomalous, we could not tell the difference between normal system activity and activity that could predict an upcoming failure.</p><p>Anomaly detection as it is, up until recently, had mostly involved different feature extraction techniques implemented for usage in classic anomalies detection models such as IsolationForest or OneClassSVM and many more. The idea is basically that we extract relevant features from the text that could be relevant for discriminating between normal and anomalous logs. The problem with this technique is that we assume many things about the distribution of our data. Moreover, this technique is not as general as we would like it to be. One feature extraction technique could be relevant for HDFS logs, and another would be relevant for SQL logs. This means that there is no “universal model” for log anomaly detection.</p><p>Lately, techniques that involve deep learning have become popular. Using Recurrent Neural Networks such as LSTM or GRU has been a popular method for detecting anomalies in sequences such as the text sequences that are present in system logs. Unfortunately, RNNs lack the memory we need for a complex analysis of system logs.</p><p>In this article, I would like to explain and simplify the LogBERT method for detecting anomalies in log sequences.</p><p>To start the in-depth analysis, we will break down the transformer block, which is the main component of BERT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*1haC5PtkwcORG3PqDh0OSQ.png" /><figcaption>The Transformer Block</figcaption></figure><p>To start off, we’ll get into the embedding layer. An important component in most neural networks dealing with natural language. So how does an embedding layer work?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*8WjEtVP1ezaKPcNc9gcJYA.png" /></figure><p>Embeddings — word embeddings, to be precise, are representations of tokens in some vector space. We would like these vector representations to capture the meaning of the word itself. A great example of a type of word embedding method is Word2Vec. The goal of Word2Vec is to maximize the cosine similarity of the word embeddings that appear in the same context in a sentence [I really like eating apples. I enjoy eating tuna. =&gt; tuna and apples should have similar representations]. We won’t get into that here, but you get the idea. The goal is to find some representation of a word that would be meaningful enough when given as input to a neural network.</p><p>So how do we process a sentence into something meaningful? In our case, how do we process a sequence of words in a log message into something meaningful? Let’s dive into it.</p><p>Well, start with a running example we’ll use throughout our series of articles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/1*qVR4GRB3JlNQIPfGI1RRWQ.png" /></figure><p>We would start by tokenizing this sentence, each word would be considered a token. We then end up having a token list. Of course, in a log file, there are many more words but just consider this single log message for the example. Each word will be placed in a dictionary or a list with a number representing it as such (I’m not getting rid of all the stop words and doing other preprocessing steps just for this example):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/138/1*p5FGJpXeaTDvkskMuYOvMw.png" /></figure><p>Now, the embedding layer looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*_qsljrilAqfvYqT9QFIrew.png" /><figcaption>The Embedding Matrix</figcaption></figure><p>What we see here is an array containing vectors in each cell of the array. Essentially what happens is that when a sequence of words [1,2,3,4,5,6] is given as input to the neural network, the embedding layer translates each word index to a vector representation using the embedding layer. So the neural network itself does not see a sequence of words nor a sequence of indexes but a sequence of vectors! The embedding layer itself has a configurable embedding size (the dimension of a word representation). Just for fun, another example would be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*S4xMy5DeLdKXQU-SAiwk4Q.png" /></figure><p>This would be translated to the sequence [1,6,3,4], which would mean our embedding layer takes the vector in index no. 1 in the embedding matrix, then vector no. 6, and then no. 3 and finally, no. 4. Of course, padding will be necessary since we should have a constant length in our sequences. And the result will be a matrix that represents our sentence or sequence.</p><p>Now that we got it, let&#39;s sum it up:</p><p>The embedding layer contains an embedding matrix which basically contains a reference to a vector that should represent that word. When words are fed into the embedding layer, they are fed as sequences of indexes referring to the vectors that should represent them in the embedding matrix.</p><p>Mathematically, it can be represented as the matrix multiplication of two matrices. Matrix A is the one-hot vector representation of the <strong>words in the sentence</strong>, and Matrix B is the embedding matrix itself containing the vector representations of each word in the corpus. So A x B Should give us the full sequence of words represented as vectors.</p><p>The next part of the transformer block is position encoding. This is the part of the transformer block where we encode the information about the position of the word in the sequence. How is this done?</p><p>Given a vector V = &lt;a,b,c,d&gt;, which represents the embedding of some word X we would like to represent the word position in the sequence itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*HjXOMUQZ4ze-EIgBMOgEeQ.png" /><figcaption>The position encoding function</figcaption></figure><p>As we can see, this function is used to encode the position of a word. How is this done? Given a word sequence, the word X could be present in different positions in the sequence. Say, in an instance of a sentence, the word could be positioned in the middle as such:</p><p>Bob ate two X this morning.</p><p>In this case, X is in the middle of the sentence, and the position of X is 4 and will be encoded using the function above. If V is embedded in a 4 dimensional space as stated above V = &lt;a,b,c,d&gt; then the transformation of V will be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*toKiPlnztHSoL1EA7IX23A.png" /></figure><p>And then finally, we have our word X represented in 4-dimensional space using our embedding layer and the position encoding layer to capture the locations of the word in the sequence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*TZ-dxp7Tj7MadJakeNQ_Yg.png" /><figcaption>The attention and normalization</figcaption></figure><p>Next, our sequence, represented as a DxN dimensional matrix where D represents our embedding dimensions and N represents our sequence size, is fed into the multi-head attention layer. Let&#39;s dive into it.</p><p>What is multi-head attention? Let&#39;s start with a simple self-attention layer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/282/0*gql0pgYs2TlLEJ64" /><figcaption>Self Attention</figcaption></figure><p>Essentially, Self Attention is a function that we perform on our input matrix:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/0*UGZhHxGxe9IIHOLf" /><figcaption>Self Attention</figcaption></figure><p>We are going to break this function down, but for this article, we will ignore the denominator as it is used for normalization and is not core to understanding the idea behind the attention.</p><p>We have our <strong>self-attention</strong> over here. The process is comprised of a few stages. The first is we apply a linear transformation on our<strong> input matrix </strong>3 times — one for the <strong>Query </strong>matrix, another for the<strong> Key,</strong> and another for the <strong>Value</strong> (We’ll call them <strong>Q,K,V</strong>). Again, <strong>our input matrix is essentially the input sequence encoded as vectors. So our input matrix is being transformed into three different matrices.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*-eYhoLzNhyCbTurQt10Arw.png" /></figure><p>In the picture above, we can see that matrix multiplication is applied to the Key and Value matrix. This results in a matrix that represents our bi-directional word relations (of course, after the weights in the matrices are learned properly). This word relations matrix allows us to capture the structure and the meaning of the sentence in a way that we haven’t been able to capture in the previous sequence learning neural networks such as LSTM or GRU. This is because those types of neural networks suffer from a lack of long-term memory, while self-attention attends to <strong>relations between words all throughout the sentence</strong> like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*am_7NeI0Y4NI0vRqNQqtIw.png" /></figure><p>The attention matrix, which captures the word relations, is finally multiplied by the value matrix. Notice how each word has a “score” as to how much it is related to other words in the sentence. In the above example, the user and admin have a high relation score.</p><p>As mentioned in the paper (<a href="https://arxiv.org/abs/1409.0473">Neural Machine Translation by Jointly Learning to Align and Translate</a>), attention, by definition, is just a weighted average of values,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/124/1*MTR8J7mlC0hAjN6coguwsg.png" /></figure><p>where</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/92/1*Fw5h8BbRKgBEMrVwd_eC_w.png" /></figure><p>If we restrict α to be a one-hot vector, this operation becomes the same as retrieving from a set of elements h with index α. With the restriction removed, the attention operation can be thought of as doing “proportional retrieval” according to the probability vector α.</p><p>It should be clear that h in this context is the <strong>value (in our case, the value matrix)</strong>.</p><p>After noting this, we can see that the value matrix is multiplied by the matrix resulting from multiplying the query and the key. This ends up being the exact definition of attention, as we were using a weighted retrieval technique with the weights α being drawn from the word relations matrix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*iO7zf2byHosP_hJ66POpMw.png" /></figure><p>If we apply matrix multiplication here, we’ll see that the encoding for a sequence in the matrix on the left is multiplied by the proportional relation of each word to all the other ones.</p><p>Next, we have Multi-Head Attention. This is similar to the multiple filters we use in convolutional neural networks. The reason is that we use multiple filters to capture different patterns in our picture that could indicate whatever we are looking for in that picture. In Multi-Head Attention, we capture different possible relations in the sentence that could result in different meanings altogether. Multi-Head Attention is actually very simple once we get the hang of attention. Essentially, all we do is concatenate the resulting matrices of the attention heads like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*c3Mt-qU73p-U-08U.png" /></figure><p>Concatenation means we just attach all the matrices to each other. The final product should be a large matrix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*F2ghI_pCvNjFtIG8bnq3iw.png" /></figure><p>This part should have summed up the main components of the LogBERT and the BERT Structure. I didn’t get into all the normalization layers and scaling and all that because I thought it was not much of a key detail and didn’t want to waste time writing about it. If anyone is confused about it, they can read up about it somewhere else.</p><p>In the next part, I want to cover the final LogBERT architecture and loss function so we can see how it all fits together. Thanks for reading so far.</p><p>You&#39;re invited to check out the next part:</p><p><a href="https://medium.com/@davidschiff_35251/logbert-explained-in-depth-part-ii-f659abde9ebf">LogBERT In Depth: Part II</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=771463d7beda" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/logbert-explained-in-depth-part-i-771463d7beda">LogBERT Explained In Depth: Part I</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Detecting Web Attacks Using A Convolutional Neural Network]]></title>
            <link>https://infosecwriteups.com/detecting-web-attacks-using-a-convolutional-neural-network-c778c73e2e2a?source=rss-237e2d2315e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c778c73e2e2a</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[David Schiff]]></dc:creator>
            <pubDate>Thu, 06 Jan 2022 11:58:00 GMT</pubDate>
            <atom:updated>2022-01-07T07:54:47.484Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong></p><p>Today we’re going to talk about Convolutional Neural Networks and the way they can be used in the cyber security domain. As some of you may know, Machine Learning applications for cyber security have been getting pretty popular in the past few years. Many different types of models are used to detect varying types of attacks.</p><p>The specific attack vector we’ll be focusing on today is web exploitation. Since most apps nowadays are web apps, and since they are exposed to the world wide network, many cyber attacks are targeted at exploiting the public facing web applications. Some examples of web exploitation techniques are attacks such as SQL injection, where an attacker tries to exploit the input of the web page such that sensitive data may be queried or changed by injecting SQL into certain areas of input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*ZJXZUtvgB93mikxDmWF_ng.png" /><figcaption>Image by author</figcaption></figure><p>In the example above, a specific crafted URL query is being sent to a web server in order to exploit their input and query sensitive data.</p><p>Another type of web exploitation technique is XSS (cross site scripting) which is an attack that enables attackers to inject client-side scripts into web pages viewed by other users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*3usjJa6C9S2lU_H_alW-gA.png" /><figcaption>Image by author</figcaption></figure><p>In the example above, an HTML tag is passed into the URL as the attacker is trying to send a string containing HTML that will later be parsed by another client and code may be executed on his workstation.</p><p>I propose using a machine learning model to detect these attacks. I’ll train the model on a dataset found on github. The dataset contains samples of web attacks. It contains queries which are not malicious and some which are, I highly recommend checking it out.</p><p><a href="https://github.com/faizann24/Fwaf-Machine-Learning-driven-Web-Application-Firewall">GitHub - faizann24/Fwaf-Machine-Learning-driven-Web-Application-Firewall: Machine learning driven web application firewall to detect malicious queries with high accuracy.</a></p><p>As you can see below, here is an example of some queries in the dataset</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TSIEzgSllT3DIKWVEd1NGg.png" /><figcaption>Image by author</figcaption></figure><p>Essentially these are all just URLs directed at some web application.</p><p>The model we will use is a Convolutional Neural Network to detect the malicious requests.</p><p><strong>Why Convolutional Neural Networks?</strong></p><p>CNN’s are often used in the vision domain. An example of its usage is in the classical MNIST problem where its used to classify handwritten digits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*VQ5ZTghN9dl1mcES.png" /><figcaption>Image by Tensorflow</figcaption></figure><p>But the obvious question that comes to mind is how these neural networks can be used to classify if a URL has a malicious intent? It is a very good question and its weird because images are essentially matrixes that contain cell values between 0–255 which vary the degrees of black-white. These values are then inputted into a complex function ( neural network ) which outputs the relevant information about the image. For example, in the MNIST problem the neural network would have to know how to classify digits, so an image is given as input and a digit would be given as output. For a more in depth explanation of how Convolutional Neural Networks work, check out this article: <a href="https://towardsdatascience.com/convolutional-neural-networks-explained-9cc5188c4939">https://towardsdatascience.com/convolutional-neural-networks-explained-9cc5188c4939</a></p><p>The question still remains, how do we encode the data of a URL into data that a convolutional neural network can work with?</p><p>Essentially what we are going to do is use the Unicode encoding of each character (the number in the Unicode table that represents the character). This is going to be part of our preprocessing as the neural network does not really understand words, rather, it is a function that understands mathematical objects such as numbers, vectors and matrixes. The neural network then learns the features necessary to differentiate between malicious and non malicious queries based on this encoding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*ONHaEcTWb7d_9unkUAWF_A.png" /><figcaption>Image by author</figcaption></figure><p>This is<strong> a much better option</strong> in comparison to other encoding types such as character embedding, word embedding and obviously one hot encoding. The reason that it’s better is that its very efficient in storage. A normal character embedding will usually encode a character into some vector which is already more costly than just embedding a character in its Unicode numerical representation. Not to even mention word embeddings which are much more difficult in this situation because we are dealing with URLs, not sentences.</p><p>We’ll format the encoded queries into 28x28 matrixes so it will be easier to use with our pre-existing MNIST neural network (Yes we’re taking almost the same architecture).</p><pre>from keras.models import Sequential,Model</pre><pre>from keras.layers import Dense, Conv2D, Flatten, MaxPool2D</pre><pre>model = Sequential()</pre><pre>model.add(layers.Input(shape=(28,28,1)))</pre><pre>model.add(Conv2D(64, (5, 5), activation=&#39;relu&#39;, kernel_initializer=&#39;he_uniform&#39;))</pre><pre>model.add(layers.BatchNormalization())</pre><pre>model.add(Conv2D(32, (5, 5), activation=&#39;relu&#39;))</pre><pre>model.add(layers.Dropout(0.2))</pre><pre>model.add(MaxPool2D((3,3)))</pre><pre>model.add(Flatten())</pre><pre>model.add(Dense(100, activation=&#39;relu&#39;, kernel_initializer=&#39;he_uniform&#39;))</pre><pre>model.add(Dense(2, activation=&#39;softmax&#39;))</pre><pre># compile model</pre><pre>model.compile(optimizer=&#39;adam&#39;, loss=&#39;categorical_crossentropy&#39;, metrics=[&#39;accuracy&#39;,metrics.Recall(),metrics.Precision()])</pre><p>Finally, the preprocessing for the dataset we’ll use the generate dataset function I wrote which gets a dataset of raw commands and labels and encodes everything into UNICODE and attaches labels.</p><pre>def generate_dataset(df):</pre><pre>tensorlist = []</pre><pre>labelist = []</pre><pre># Generating our dataset sample by sample</pre><pre>for row in df.values:</pre><pre>query = row[0]</pre><pre>label = row[1]</pre><pre># Encode characters into their UNICODE value</pre><pre>url_part = [ord(x) if (ord(x) &lt; 129) else 0 for x in query[:784]]</pre><pre># Pad with zeroes the remaining data in order for us to have a full 28*28 image.</pre><pre>url_part += [0] * (784 - len(url_part))</pre><pre>maxim = max(url_part)</pre><pre>if maxim &gt; maxabs:</pre><pre>maxabs = maxim</pre><pre>x = np.array(url_part).reshape(28,28)</pre><pre># label y</pre><pre>if label == 1:</pre><pre>y = np.array([0, 1], dtype=np.int8)</pre><pre>else :</pre><pre>y = np.array([1, 0], dtype=np.int8)</pre><pre>tensorlist.append(x)</pre><pre>labelist.append(y)</pre><pre>return tensorlist,labelist</pre><p>Finally, now that we have our dataset and everything is ready it should be about time to train and test the model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vA26Gt1xbXskv8GS1DJ1qw.png" /><figcaption>Image by author</figcaption></figure><p>As you can see in just about 2 epochs the neural network is already performing incredible.</p><p>Check out the code on github:</p><p><a href="https://github.com/tentacool9/MLWAF/tree/master">https://github.com/tentacool9/MLWAF/tree/master</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c778c73e2e2a" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/detecting-web-attacks-using-a-convolutional-neural-network-c778c73e2e2a">Detecting Web Attacks Using A Convolutional Neural Network</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Memory Analysis For Beginners With Volatility — Coreflood Trojan: Part 3]]></title>
            <link>https://medium.com/purple-team/memory-analysis-for-beginners-with-volatility-64298c8b186?source=rss-237e2d2315e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/64298c8b186</guid>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[David Schiff]]></dc:creator>
            <pubDate>Sun, 23 May 2021 05:48:55 GMT</pubDate>
            <atom:updated>2021-05-26T15:15:54.752Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome back. In order to continue our forensic investigation of the Coreflood Trojan we need a little recap from part 2.</p><p>We left off last time looking at handles used by the IEXPLORE process. We checked out the handles because we know IEXPLORE is doing something malicious. This is because we saw it had some code injected in it.</p><p>Just to remind everyone, this is what the IAT of the injected module looked like. We can clearly see the imported functions used by the module using the <strong>impscan </strong>command. Check out my last post if you don’t remember.</p><p><a href="https://medium.com/bugbountywriteup/memory-analysis-for-beginners-with-volatility-coreflood-trojan-part-2-42bdb46683f2"><strong>Memory Analysis For Beginners: Coreflood Trojan Part 2</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/0*d94AMRguKxC3eEqf.png" /><figcaption>The IAT (imported functions) of the injected module.</figcaption></figure><p>After seeing how suspicious IEXPLORER.EXE is I decided it may be a good Idea to continue investigating whatever was injected into memory over there, its always a good idea to use strings.exe which will give us an idea of what’s going on in this injected piece of code. Sometimes developers will leave strings in their code that may tell us something about whatever is running in the code without the need to disassemble it.</p><p>Let’s hop over to that VAD section that we discovered in the last article with malfind:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0bZKEgF5T9hqhJlcSzGhDg.png" /><figcaption>The MZ head is missing (read last article)</figcaption></figure><p>Lets take that base address we see here and use vaddump to dump out that memory section for further analysis:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*tOzT72vIQ22WOQ0Zi_FuYg.png" /><figcaption>We specify the process id and the base address of that memory section. -D is for specifyin the output directory of the file created.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8bVnUSGVch8gcz6kunXOzA.png" /></figure><p>And the output is a memory dump file. We can use strings on it now (get strings here):</p><p><a href="https://docs.microsoft.com/en-us/sysinternals/downloads/strings">Strings - Windows Sysinternals</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*DRh38hnb8T0pk4icZQkkTQ.png" /></figure><p>Now that we dumped out the strings found in that memory section let’s see what we got. In the beginning of the text file you will see a lot of garbage, scroll down and look at this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*OPNx5u5leP3tnA78LgJFww.png" /></figure><p>We can see some clearly suspicious strings. It seems as though there is some sort of regex check for the url submitted by the target user maybe to steal accounts related to that user in those sites. The theory that we’re dealing with a spyware seems very probable.</p><p>Another thing we could clearly see in the strings file is a possible search for browsers installed on the target host.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*rDVcoqQhaPB189Vpr1w8mw.png" /></figure><p>It seems as though other browsers are targets for code injection. Notice how we see explorer.exe here as well. To check the theory that these are code injection targets — lets confirm it using malfind.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*PJWknwwjRTXZ25C-55MeUQ.png" /><figcaption>This time we’ll use malfind to find anything suspicious in explorer.exe</figcaption></figure><p>And here we have a section with EXECUTE_READWRITE permissions which is always a suspect for code injection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*xCnVyVfexvF067dl-htAhQ.png" /></figure><p>Lets dump this section and see if we have another piece of information. Maybe we’ll find the same code that was injected into IEXPLORE.EXE here as well? Unfortunately it seems as though this is not a case of code injection as the size of the memory section (after dumping) is too small compared to what we dumped out of IEXPLORE.EXE. Also, strings turned up empty :(. It still could be that some code was injected here or maybe whatever was there was paged…</p><p>If we observe our text file we could see something that could also be the output that is generated for the commander if there is a C&amp;C ( A host that can control and send commands to clients containing the malware ). I suspect there is in fact a C&amp;C from what I can see in the rest of the strings here. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C01cZO2gooBi1kE-RW2anA.png" /></figure><p>These definitely look like some sort of output strings that would be generated for someone who is trying to run commands on a host. It looks like the controlling server would have full control over processes that start and stop on the host.</p><p>Lets refocus and try and find how this malware behaves.</p><p>As always when dealing with rootkits its good to think about the different things we want to watch out for. The first thing we want to figure out is persistency. How does our rootkit survive a reboot? What runs the malicious file ( if exists ) each time? Its good to look for the persistency method as this can help us immediately to mitigate the threat. As we can see in the strings found in the injected module, something very important shows up:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*kTmkp0yaepVO1x5jwLUiCA.png" /><figcaption>The RunOnce key is crucial</figcaption></figure><p>The runonce key is a classic move for persistency as whatever is written in that key is run on system startup and deleted. The rootkit can write itself to that key each time to make sure it runs as soon as the system starts up. We can see rundll32 it could likely be that this is what is executed in the runonce key and we might expect to a malicious dll on our target host.</p><p>Another persistency method that could be used here is AppInit_DLLs.</p><p>AppInit_DLLs is a mechanism that allows an arbitrary list of DLLs to be loaded into each user mode process on the system. This could be easily abused by malware to gain persistency by simply placing their malicious dlls in the proper registry location — HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion \Windows key in the registry determine the behavior of the AppInit_DLLs infrastructure ( What will be loaded and how ). Unfortunately, these registry keys are not to be found in memory.</p><p>As we have already suspected — above you can see more strings that have to do with dlls and the registry. It could be that these are just logs or debug prints that have to do with the persistency mechanism. It will be a good idea to check out what we can find about dlls in the system32 directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*bf_ZuFj1B-6SqPeJiY-Xeg.png" /></figure><p>And look what we found here a string that looks really suspicious. In the system32 directory a dll file that looks really suspicious. Its not even a dll its a dIl with an I, good job.</p><p>I used filescan to see if I could get a hold of the file in memory to dump it out later on and analyze it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*3jD9txOQku7zRl__DhmECQ.png" /></figure><p>And here we go, found the dll.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_aWHoDhhF1ms-o3Ym0JdrQ.png" /></figure><p>Next, We can use dumpfiles to dump out the file and investigate it further.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*WwWa-yeb83O5KMprnwfzQQ.png" /><figcaption>Specify the physical memory offset using -Q</figcaption></figure><p>Using pestudio (a portable executable analysis tool — get it here: <a href="https://www.winitor.com/">https://www.winitor.com/</a>) we can extract some futher information about the dumped file. We can see that it is indeed a DLL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*aI9TKRHtSuStb-ihTjgpdQ.png" /></figure><p>Looks like it is packed as we can see there are sections that indicate a packer was used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z_l4oY0szgBZKV7ZZrRSuQ.png" /><figcaption>UPX is a known executable packer.</figcaption></figure><p>This leads us to suspect that this module is indeed malicious. Moreover, I looked in my system32 directory and there is no module named comsbap.</p><p>To summarize, we found the persistency mechanism and we finally have some concrete ideas about this malware. It seems as though it has some spyware capabilities as well as coming with a full shell like mechanism for whoever is controlling these hosts using this malware.</p><p>Next time we will dive deeper into the full capabilities of the malware and get some more concrete evidence for what the dll we discovered does and try to analyze exactly whatever is going on here.</p><p>It may be a good idea to search for this module and see if it is loaded in any processes. If it’s loaded in a few processes this might have to do with Appinit_Dlls and we would have proof of persistency using Appinit_Dlls. You can try it out yourself and find out.</p><p>In the upcoming articles we will try and create a full timeline for whatever is going on in our target host machine, stay tuned.</p><p>Thanks for reading and see you next time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64298c8b186" width="1" height="1" alt=""><hr><p><a href="https://medium.com/purple-team/memory-analysis-for-beginners-with-volatility-64298c8b186">Memory Analysis For Beginners With Volatility — Coreflood Trojan: Part 3</a> was originally published in <a href="https://medium.com/purple-team">Purple Team</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Memory Analysis For Beginners With Volatility — Coreflood Trojan: Part 2]]></title>
            <link>https://infosecwriteups.com/memory-analysis-for-beginners-with-volatility-coreflood-trojan-part-2-42bdb46683f2?source=rss-237e2d2315e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/42bdb46683f2</guid>
            <dc:creator><![CDATA[David Schiff]]></dc:creator>
            <pubDate>Sat, 17 Oct 2020 19:49:56 GMT</pubDate>
            <atom:updated>2020-10-17T21:14:33.090Z</atom:updated>
            <content:encoded><![CDATA[<h3>Memory Analysis For Beginners With Volatility</h3><h4>Coreflood Trojan: Part 2</h4><p>Hello everyone, welcome back to my memory analysis series. If you didn’t read the first part of the series — go back and read it here:</p><p><a href="https://medium.com/@davidschiff_35251/memory-analysis-for-beginners-with-volatility-coreflood-trojan-part-1-89981433eeb6">Memory Analysis For Beginners With Volatility — Coreflood Trojan: Part 1</a></p><p>Just to recap quickly:(if you don’t want the recap skip to the next section) Last time we left off at finding out what the malicious code that was injected into IEXPLORE.EXE process was doing. We used the <strong>apihooks </strong>command to list all instances of hooking in our host’s machine. Just to remind you, here’s what we found:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/0*KLzUQ-LBmCsHD64u.png" /><figcaption>An example of a classic IAT hook. (Explained in the last post)</figcaption></figure><p>As we can see above is our piece of code that was hooked. The module that was hooked is kernel32.dll. The <strong>CALL</strong> instruction calls a different function that was injected into memory instead of LoadLibraryW. It executes this beautiful malicious piece of code (which you can see for yourself — If you dont remember how, go back to the previous post):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/0*6BrRHasdhGJ07fgB.png" /></figure><p>In order to figure out what this piece of code does, my first instinct is to use the <strong>vaddump </strong>command. This command enables me to dump out a section of memory. I can use it to dump out the module from memory and disassemble it using IDA ( or some other disassembler )</p><p>One small problem though: In the previous post I used the <strong>malfind</strong> command which is supposed to find modules injected into memory. Unfortunately we ended up not seeing any actual module in memory. What we saw was this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*oerVR_f28ek9nVvhHz9VFw.png" /><figcaption>The output of the malfind command, as we can see over here there is <strong>no MZ header</strong></figcaption></figure><p>Usually when a module is injected into memory it should have the MZ header which would be a good sign for us that the injected module was not tampered with in memory or that the header was not paged. It could be that the module has had its header cleared out from memory for obfuscation reasons. It’s a pretty good move to make it hard to investigate this malware since it will take longer to reconstruct everything in order for us to be able to disassemble the module.</p><p>Fortunately, we can use the <strong>impscan </strong>command which allows us to retrieve information about API calls made by the code to other modules in order to understand the functionality of the injected code.</p><p><strong>impscan </strong>works by scanning the process memory for calls to functions like JMP [&lt;address&gt;] or CALL [&lt;address&gt;] which basically tells us that the <strong>function address </strong>is stored in the &lt;address&gt; ( a pointer to an address ) in memory. These kind of calls are sometimes used for <strong>retrieving a function address from the IAT </strong>which is an array that contains the addresses of imported functions. What volatility can do with that is follow up on these calls to see <strong>what the IAT stores</strong> and to which functions it points us to in the other modules loaded in memory.</p><p>Now that we know how <strong>impscan</strong> works lets go ahead and use it, and we’ll specify the <strong>IEXPLORE.EXE</strong> process id as a command argument since <strong>our malicious code is loaded in it </strong>and we want to find what it does. Also, we’ll need to provide the <strong>base address for the malicious module loaded into memory </strong>so volatility will know where to scan for imports.</p><p>How do we get the base address of our malicious module?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*Jr7cU4LZ9I-Vu4LOZJkeVw.png" /></figure><p>We’ll combine a hook example from <strong>apihooks </strong>and a quick search in the <strong>vadinfo </strong>command output (see previous post for an explanation of the vad) to get the base address of the malicious code.</p><p>Now that we have everything we need, lets run the impscan command</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vpx8dKI6H6T-11a31b_gYw.png" /><figcaption>impscan command</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*7s7Kg6bUozkLwU34AFKQ2w.png" /><figcaption>impscan command output</figcaption></figure><p>We can now see the beautiful list of imported functions. We can also see the IAT column which shows us the address of the element in IAT array and the and on its right side the address of the imported function contained in that array element. <strong>impscan </strong>also shows us the names of the imported functions, this could help us understand what our code does by the name of the function.</p><p>Here’s an example of how to use the <strong>impscan </strong>command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*rdVsw-owbwaCGR-Yf_cCaQ.png" /><figcaption>A comparison of the IAT to the disassembled code, a call from our code leads us to the address contained in the IAT.</figcaption></figure><p>As we can see, we can look at the output of the impscan command and compare it to the injected code to find out what each function call is doing. For example , in the exhibit above a call to FreeLibrary is made by the injected code. FreeLibrary frees the loaded dynamic-link library (DLL) module and, if necessary, decrements its reference count. When the reference count reaches zero, the module is unloaded from the address space of the calling process and the handle is no longer valid.</p><p>We now have the ability to go through the injected code and understand its functionality. One problem with this method is that it takes a while to go through all this assembly code in order to get the bigger picture. So another way we can use <strong>impscan </strong>is just to look at the imports and understand what functions the module uses. Just by seeing the <strong>function names </strong>and <strong>not necessarily </strong>going through the code logic by reading assembly code we can get an idea of what this malware is trying to do.</p><p>Lets highlight some suspicious functions that <strong>impscan</strong> gave us and follow up on what the malware may be doing using other volatility commands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*JFhGMiWHwcrjTKilXJn5GA.png" /></figure><p>There are many interesting functions used by our malicious module. For those of you who already have experience with volatility and forensics, don’t worry ill try and cover everything. But first I want to start with some simple stuff; The Registry.</p><p>We can see the malware imported some API to use the Registry. As you all probably know, the Registry contains sensitive information and settings. Some malware strains use the registry for persistency by adding a executable file to run on startup by editing the autorun key. It could be that in this case the malware is trying to steal sensitive information by checking the registry for where some files it may want to exfiltrate are stored.</p><p>Volatility gives us a nice command called <strong>handles. </strong>This command enables us to take a look at the handles used by a process. For those of you who don’t know, Windows uses objects to represent and access system resources, including files, devices, keys and so on. Essentially, an object is accessed by using a <strong>per-process handle table in the kernel</strong>. Opening an object results in adding a pointer to the object in the handle table. Volatility uses this fact and scans the memory for handles.</p><p>We’ll use the <strong>handles</strong> command with a pipe and filter out the output to contain only Registry keys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8gFkJnX8L5yZVx-xjACb7w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IHztx-keHNayYKj6bvifuA.png" /></figure><p>If you are trying this at home, you can probably see a longer list of keys opened, I just cut off a small part of the list that seemed interesting.</p><p>So off the top of my head I can say some interesting things about what we can see here. First things first, we can see a key ending with TYPEDURLS. This key could just be regularly used by Internet Explorer (As it should be) but it could also be abused by a trojan to get information about websites used by their victim. This is a good spying technique, especially since the code is injected into Internet Explorer. Another similar key is RUNMRU which lists recently run programs, a hacker that wants to gain insight into a users activity may want to check it out and exfiltrate this info as well.</p><p>Another interesting thing is that the DRIVERS32 registry key is used somehow. This may hint at the fact that this malware may have a driver installed on our host as well and may be using it somehow. I also saw some registry keys related to IE Security settings being used, this may be another method of an attacker to lower security measures on the host’s computer and make it more susceptible to other attacks.</p><p>Just to conclude this part I want to point out that we didn’t see strong evidence for malicious activity in the registry, there were no custom registry keys used (At least nothing we saw). We can only speculate what this malware is doing in the registry. In the next part of the series I want to use more tools given to us by volatility in order for us to be able to understand exactly what is the goal that the malware is trying to achieve.</p><p>Thanks for reading the second part of my memory analysis series!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42bdb46683f2" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/memory-analysis-for-beginners-with-volatility-coreflood-trojan-part-2-42bdb46683f2">Memory Analysis For Beginners With Volatility — Coreflood Trojan: Part 2</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Memory Analysis For Beginners With Volatility -  Coreflood Trojan: Part 1]]></title>
            <link>https://infosecwriteups.com/memory-analysis-for-beginners-with-volatility-coreflood-trojan-part-1-89981433eeb6?source=rss-237e2d2315e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/89981433eeb6</guid>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[memory-analysis]]></category>
            <dc:creator><![CDATA[David Schiff]]></dc:creator>
            <pubDate>Fri, 02 Oct 2020 08:32:26 GMT</pubDate>
            <atom:updated>2020-10-10T13:22:54.654Z</atom:updated>
            <content:encoded><![CDATA[<h3>Memory Analysis For Beginners With Volatility Coreflood Trojan: Part 1</h3><p>Welcome to my series on memory analysis with Volatility. To start off the series I want to make sure we’re all sorted out with our knowledge of Windows internals. If you’re not sure you know about any of these subjects, you should go ahead and read about them a little.</p><p>You need to know the basics of how memory works in Windows. Ill try to explain as much as I can in the article. Other than that, whatever you don’t understand you’re welcome to read up on!</p><p>Reading list:</p><ul><li>Kernel Mode</li><li>User Mode</li><li>Virtual Memory</li><li>Windows Processes</li></ul><p>A little bit of background:</p><p>Memory forensics (sometimes referred to as memory<strong> </strong>analysis) refers to the analysis of volatile data in a computer’s memory dump. Information security professionals conduct memory forensics to investigate and identify attacks or malicious behaviors that do not leave easily detectable tracks on hard drive data.</p><p>Through the practice of memory forensics, experts are supplied with runtime system activity, such as open network connections or recently executed commands &amp; processes.</p><p>Before programs are executed on the computer, they are loaded into the memory making the use of memory forensics of high importance. Each program or data which is created, examined, or deleted is stored in the RAM. This includes images, all web-browsing activity, encryption keys, network connections, or injected code fragments. In many instances, certain artifacts can only be found in the RAM, such as open network connections present during the time of the crash. Attackers can develop malware which only resides in the memory, rather than the disk, making it virtually invisible to standard computer forensic methods. This makes the need of memory forensics tools in high demand.</p><p>Volatility is an advanced memory forensics framework. It gives the investigator many automatic tools for revealing malicious activity on a host using advanced memory analysis techniques. It is implemented in python and is open source! I recommend checking out their git repository.</p><p>Volatility’s git repo and documentation:</p><p><a href="https://github.com/volatilityfoundation/volatility">GitHub - volatilityfoundation/volatility: An advanced memory forensics framework</a></p><p>Volatility’s malware-specific commands documentation</p><p><a href="https://github.com/volatilityfoundation/volatility/wiki/Command-Reference-Mal">Command Reference Mal</a></p><p>In this series I want to walk through a forensic search of the Coreflood trojan.</p><blockquote><strong><em>Coreflood</em></strong><em> is a </em><a href="https://en.wikipedia.org/wiki/Trojan_horse_(computing)"><em>trojan horse</em></a><em> and </em><a href="https://en.wikipedia.org/wiki/Botnet"><em>botnet</em></a><em> created by a group of Russian hackers and released in 2010. The FBI included on its list of infected systems “approximately 17 state or local government agencies, including one police department; three airports; two defense contractors; five banks or financial institutions; approximately 30 colleges or universities; approximately 20 hospital or health care companies; and hundreds of businesses.”</em><a href="https://en.wikipedia.org/wiki/Coreflood#cite_note-1"><em>[1]</em></a><em> It is present on more than 2.3 million computers worldwide and as of May 2011 remains a threat. — Wikipedia</em></blockquote><p>Download here (the .vmem file):</p><p><a href="https://github.com/mgoffin/malwarecookbook/blob/master/16/6/coreflood.vmem.zip">https://github.com/mgoffin/malwarecookbook/blob/master/16/6/coreflood.vmem.zip</a></p><p>The goal of this series is to understand what this malware is doing by using volatility and trying to explain my findings and my methods for memory forensics. I’ll try to uncover all the forensic artifacts I can about Coreflood in order to understand what the motive behind this malware is exactly. I hope to learn some new things from this forensic analysis and teach you some new things!</p><p>To start the investigation I want to begin with a simple listing of processes running on the host machine just to see if there is any obvious suspicious process running using the <strong>pslist </strong>command.</p><p>Windows uses a circular double linked list of _EPROCESS structures to keep track of all the active processes. This list lies in the Kernel. Volatility uses this fact and looks for the PsActiveProcessHead pointer which points to the start of the kernel’s list of _EPROCESS structures. Volatility walks along this lists to enumerate the processes running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cph05olSj-8-wc-ZQOCZJA.png" /><figcaption>List of processes running on host: volatility -f coreflood.exe pslist command output</figcaption></figure><p>As we can see it seems like everything is normal but a few things catch the eye. Internet explorer is running and so is cmd, it seems like a proper thing to do is to check outbound connections, maybe the malware is disguised as Internet Explorer and uses the fact that Internet Explorer communicates regularly to hide its own communication to a C&amp;C?</p><p>It might be a good idea to check out what cmd is up to over there but we’ll get to that later.</p><p>An intuitive action to take is to see the outbound connections. If we see that there are no outbound connections going through IE that look suspicious we might need to look elsewhere for out malicious activity.</p><p>I used the <strong>connscan </strong>command to check out previously terminated and currently active connections.</p><p>“To find _TCPT_OBJECT structures using pool tag scanning, use the connscan command. This can find artifacts from previous connections that have since been terminated, in addition to the active ones.” — Volatility documentation</p><p>The way this works is by scanning the physical memory for the four-byte signature 0x54455054 (“TCPT”) and parsing out the next 28 bytes as the full _TCPT_OBJECT .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*XsFE7id8B_4q8YGNhRQiNg.png" /><figcaption>volatility -f coreflood.vmem connscan output</figcaption></figure><p>It seems like the host was communicating legitimately, all the communication is created by pid 2044 which is IEXPLORE.EXE. I checked out the geolocation of these IPs. They were all registered under some large companies such as Microsoft, AT&amp;T and such… It could be that the data about the IPs has changed be since this is an old vmem file under investigation. It also could be some fake data about these IP addresses registered by the hackers to trick the investigators.</p><p>Just to make sure there is no malicious communication at all, we should check the inbound connections to be on the safe side. I will use the <strong>sockscan </strong>command, the sockscan command scans the memory for _ADDRESS_OBJECT . By scanning the memory for this memory structure we could get insight into previously opened and currently open sockets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*53bAcsZBJfg38id4UPppqg.png" /><figcaption>Output of volatility -f coreflood.vmem sockscan</figcaption></figure><p>As we can see there are some pretty weird inbound connections coming into pid 2044, or as we call it: IEXPLORE.EXE. This look suspicious and I think its time we take out our big guns, I suspect there may be a malware hiding in that process.</p><p>Its time to pull out Volatility’s big guns and use the powerful malware analysis tools it offers.</p><p>The first command well use is the <strong>malfind </strong>command. This command is used to find injected code inside the processes memory. It does this by looking for sections of allocated memory ( by looking at the <a href="https://www.sciencedirect.com/science/article/pii/S1742287607000503#:~:text=The%20Virtual%20Address%20Descriptor%20tree,entry%20in%20the%20VAD%20tree.">VAD tree data structure</a>) and checking if they have hints of executable code that are not mapped to any file on the disk.</p><p>“VAD nodes also reference a number of other kernel structures that may be useful to an investigator… From there, if the region is used for a mapped file (such as a loaded DLL), the corresponding _FILE_OBJECT structure can be referenced and the name of the file can be extracted. This can provide an investigator with an alternate method of listing modules loaded by a process, which can then be compared with other methods (e.g., those described by <a href="https://www.sciencedirect.com/science/article/pii/S1742287607000503#bib14">Walters, 2006</a>) to find evidence of library injection and hidden modules.” — Science Direct</p><p>The method used to check if a section of memory contains injected code is by <strong>checking the VAD for page permissions, such as execute.</strong> If a section in the memory has <strong>execute</strong> permissions and <strong>it is not mapped</strong> to any executable file on the disk, this is a clear warning for what might be a code injection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*Rm5UDEq9CO1m_Soj7e82ow.png" /><figcaption>volatility -f coreflood.vmem malfind — The command output seems like some false positives</figcaption></figure><p>As we can see in the image above, looks like the command output doesn’t really tell us much. It seems as though the output of <strong>malfind </strong>is pretty benign.</p><p>It may be that the malware did not load any explicit PE (portable executable) into memory and just injected some shellcode or that the image header is paged. It could also be that the malware cleared out the PE’s header from memory to avoid detection by calling VirtualFree on the injected DLL’s ImageBase. It could also be that this section of memory is paged or unreachable for some reason. Anyways, we can’t know for sure since there is no concrete evidence of malicious activity here.</p><p>The next command we can use is <strong>apihooks</strong>:</p><p>“ This finds IAT, EAT, Inline style hooks, and several special types of hooks. For Inline hooks, it detects CALLs and JMPs to direct and indirect locations… and calls to unknown code pages in kernel memory.” — Volatility Documentation</p><p>In order to understand what exactly is going on here we need a quick recap of IAT and EAT.</p><p>When an executable is first loaded, the Windows loader is responsible for reading in the files PE structure and loading the executable image into memory. One of the other steps it takes is to load all of the dlls that the application uses and map them into the process address space.</p><p>The executable also lists all of the functions it will require from each dll. Because the function addresses are not static a mechanism had to be developed that allowed for the these variables to be changed without needing to alter all of the compiled code at runtime.</p><p>This was accomplished through the use of an import address table (IAT). This is a table of function pointers filled in by the windows loader as the dlls are loaded.</p><p>The EAT works in the same way as the IAT, apart from the library will be exporting the functions to the image executable, in which the program will import into the IAT (I won’t get into the nitty gritty details).</p><p>These two memory structures can be manipulated by malware in order to make the executable call some other function rather than the function intended to be called.</p><p>I want to use <strong>apihooks</strong> specifically on <strong>IEXPLORE.EXE</strong> just because I am already suspecting it might have been tampered with based on the output of <strong>sockscan.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*L7vrZZPEjhfkw3VAr_IVAQ.png" /><figcaption>We’ll use apihooks and save the output in a text file</figcaption></figure><p>Suprise! Internet Explorer has been hooked a dozen times to call the same function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*LhIwcEtaXR0vM6rSZVXedw.png" /></figure><p>We can see above, the output of the command apihooks that we saved in a text file. This is one out of the other dozen of hooks to different functions. They all call the same address 0x7ff82a6e</p><p>We can see that the malware hooked LoadLibrary in WINHTTP.dll in this example.</p><p>LoadLibrary can be used to load a library module into the address space of the process and return a handle that can be used in GetProcAddress to get the address of a DLL function. LoadLibrary is a very obvious choice for hooking since we know many PE’s use other dlls and therefore import their functionality.</p><p>We need to find out what the malware is trying to achieve here. In order to do that we need to try dive into the piece of code the malware is trying to execute. Therefore, we are going to use Volatility’s <strong>volshell</strong>. Volshell is a powerful tool we can use to browse our memory. We can jump to sections of memory, see whatever is in them and then dissasemble or read whatever is inside.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qV4D2gZkD3I9hwRzc7FyFA.png" /><figcaption>Type the volshell command and then follow the flow.</figcaption></figure><p>After typing the volshell command, I used the cc(&lt;context) command to change into the memory context of certain process. I used the pid of iexplore.exe (pid=2044) as an argument to the command in order to dive into the context.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*aGGwzlommUOCuWd8RGeAXA.png" /><figcaption>The highlighted text above (top to bottom) shows us the address that was hooked and under it, also highlighted is the address the malware wants our code to go to.</figcaption></figure><p>As we can see above, the relevant address we want to disassemble in order to find out what are malware is doing. I copied this address as an argument into the volshell command dis(&lt;copied_addres&gt;) as noted above in our flow chart.</p><p>Our final output should be the malicious injected code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*RJZnbir24cxEnxGryZBWQA.png" /></figure><p>You will have to wait for the part of the series to try and find out what this malicious piece of code is doing. Maybe you can try for yourself in the meanwhile.</p><p>To sum things up for this part. We used volatility to find suspicious or malicious code running on our host’s machine. We started with some basic actions such as making sure there isn’t anything suspicious that we can spot immediately such as a suspicious process or some traffic to an unusual IP address. We ended up pulling out our big guns to try and see if our malware is hiding by injecting code into innocent processes and we discovered some interesting things. In the next part I’ll dive deeper into the code and try to see what this malware is trying to achieve exactly.</p><p>Hope you had a good read, see you in the next one.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89981433eeb6" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/memory-analysis-for-beginners-with-volatility-coreflood-trojan-part-1-89981433eeb6">Memory Analysis For Beginners With Volatility -  Coreflood Trojan: Part 1</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Mind And Evolution: How Did Consciousness Evolve?]]></title>
            <link>https://medium.com/@davidschiff_35251/the-mind-and-evolution-how-did-consciousness-evolve-79297c2f2f02?source=rss-237e2d2315e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/79297c2f2f02</guid>
            <dc:creator><![CDATA[David Schiff]]></dc:creator>
            <pubDate>Sat, 05 Sep 2020 17:37:21 GMT</pubDate>
            <atom:updated>2020-09-05T17:37:21.822Z</atom:updated>
            <content:encoded><![CDATA[<p>The Mind And Evolution: How Did Consciousness Evolve?</p><p>To those of you who missed my previous post about the mind, I’ll do a quick recap:</p><h4>The mind is the feeling of subjectivity that we all have, the feeling of what it’s like to be us.</h4><p>When you wake up with a headache in the morning, you can’t ignore it. You feel that feeling of “what’s it like to have a headache”. That feeling of “what’s it like to — ” is called qualia.</p><p>In some sense, qualia defines conscious experience, Without it, we would all be computers with no subjective experience or conciousness of reality at all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TAo0ue1R4jOgpJgKSHlCFg.jpeg" /></figure><p>The question which I want to pose in this article has been on my mind for quite some time</p><h4>How did Evolution give rise to subjective experience?</h4><p>This question seems simple at first. What do you mean “how did it evolve”? Same as all other things that evolved, just like a bird evolved to have wings… that’s how conciousness evolved!</p><p>The problem with that simple answer is that the laws of evolution don’t seem to possibly apply for consciousness. As we know, evolution works by the simple mechanism known as survival of the fittest. An organism that is most fit is more likely to survive and pass it’s genes to the next generation.</p><p>Mutations in genes are the cause for diversity among organisms. Eventually a mutation could cause a positive effect in an organism which would make it more fit for survival in certain conditions. Then, nature “selects” that organism since it is more likely survive and pass on it’s genes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*y-4To2kj4a7UqDMUQQD5aw.png" /></figure><p>Every mutation that occurs in an organism and is indeed beneficial for the survival of that organism, must have some sort of functionality that betters it’s odds for survival. For example a bird has wings ( physical) and it uses the wings to escape predators and get to food faster (functional). It’s pretty straightforward, we can understand why physical attributes that are functionally beneficial for survival are “selected” by nature. After all, if a mutation would not benefit survival at all, the new physical attribute caused by the mutation would most likely not live on and be passed down to later generations.</p><p>What about Consciousness? It has to have a function in order to be “selected” by nature right?</p><p>That’s where things get complicated. To answer this question, we’ll do a thought experiment called “The Philosophical Zombie”.</p><p>The thought experiment goes like this; imagine some possible world where you are not conscious. All your friends are not conscious as well, but you are all acting the same. You would all watch TV, eat snacks, go out to a bar… But you would all not be conscious, just robots being robots.</p><p>What this philosophical thought experiment implies is that the mind has no functionality. Our twin in our imaginary world behaved the same and looked the same. In fact , the only difference between us and our imaginey-experiment twin is that our twin has no subjective experience.</p><h4>S<strong>ince</strong> <strong>our behavior or physical appearance doesn’t change when we are unconscious it is safe to arrive at the conclusion that there is no underlying functionality in consciousness.</strong></h4><p>If consciousness is not a physical thing and has no functionality how did it evolve then?</p><p>There are a few theories to answer that question, most are easier to grasp, some really tough.</p><h3>Epiphenomenalism</h3><p>This theory states that consciousness itself is not functional in any way but is an <em>epiphenomenon </em>of another attribute that <strong>does</strong> have functionality.</p><p>You can compare it to boiling water. When you boil water, the water heats up like you wanted, but a side effect of boiling water is steam. Comparably, consciousness is the “steam” of some other functionality in the brain. It could possibly be that because of the high cognitive ability us humans have as a result of brain structure has some sort of consciousness “side effect” or “steam”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZUo9DY0cQjGWB7mXeEqFlg.png" /></figure><p>The image above explains it pretty well, as conscious states are side effects of material states our problem with evolution fades away. To refresh our memory, our problem was “how did evolution give rise to something with no inherent function” and the answer epiphenomenalism gives us is that consciousness in itself really does not have any sort of function, but it is a side effect of something that does have an evolutionary functionality.</p><p>For arguments against epiphenomenalism check out <a href="https://plato.stanford.edu/entries/epiphenomenalism/#NatSel">Stanford’s Encyclopedia of Philosophy</a></p><h3>Panpsychism</h3><p>This theory says that everything is conscious in the universe. Every single atom in the world has some form of consciousness. So consciousness itself is not some sort of special property of the brain and therefore must have some sort of special functionality to have evolved. Instead, consciousness is something far more basic, everything has some form of consciousness.</p><p>This idea is ancient, it has roots dating back thousands of years. The “world soul” may be the age old answer to our question.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*HYuJw-VpizPjTbnSyrwLMg.jpeg" /></figure><p>If panpsychism is true, it could lead to immense changes to the way we act in the world. Would vegans a cause for suffering of plants just like meat eaters are for meat? After all , plants are conscious! But hold up, it’s not only plants that should be a cause for worry, what about our every day regular objects? Could we treat our desk the same way we do every day? What does it feel like for a desk to have books thrown on it? We need to be careful!</p><p>We should put these thoughts on hold for a second, since we don’t even know what kind of consciousness non human being have. It could be very different from our type of consciousness… Something completely out of our minds understanding. After all, what does consciousness without a sensory system feel like?</p><p>I hope we have questions to these questions some day. I think these questions might lead us to understand our true purpose in the universe. Both answers I gave have opposing outcomes. Epiphenomenalism leaves us feeling like a huge mistake made by a randomly caused universe that managed to create life forms by chance that developed self awarenesses in order to survive. The other theory, Panpsychism, has us feeling enchanted by the idea that everything around us is aware in some sense, just like us, and it may be true that all ancient religions were right about the afterlife, God and the nature of the world.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79297c2f2f02" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Mind-Body Mystery]]></title>
            <link>https://medium.com/@davidschiff_35251/the-mind-body-mystery-3aacce1264b0?source=rss-237e2d2315e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/3aacce1264b0</guid>
            <dc:creator><![CDATA[David Schiff]]></dc:creator>
            <pubDate>Sun, 02 Aug 2020 19:40:45 GMT</pubDate>
            <atom:updated>2020-08-02T20:23:04.989Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hULoUsfE3liqupIYU9dTsA.jpeg" /></figure><p>Hey there. You, are a conscious being. You felt it when you woke up this morning, You feel it now.</p><p>You, are you. You know what it’s like to be you, and only you can know it. Only you can experience what it feels like to be you. Sounds pretty simple right?</p><p>Let’s think about that for a second. If I told you that I could let you see what your friend is experiencing while they’re eating an apple, what I would do is take you and your friend to a lab and let the scientists in the lab scan your friend’s brain by using a super advanced technique to map out their brain activity. The scientists would achieve this by tracking every neuron in your friend’s brain and seeing which neurons fire at each moment while they’re being fed an apple. This whole process takes a while, but after a few minutes the scanning comes to a stop.</p><p>The chief scientist comes over to you and says: “come look at your friend’s experience of eating an apple!”. You follow the scientist and both of you sit down in front of the monitor and you see something amazing.</p><p>“Look”, he says, “Those flashing lights on the screen are the neurons being fired in the gustatory cortex, the part of the brain responsible for the sensation of taste”.</p><p>You stare at the monitor in wonder and awe, but you start to think to yourself — Hey this is not what I came for… where is my friend here? Where is he eating an apple? This is not what it feels like to eat an apple! All this is … It’s all neurons simply flashing on the screen…</p><p>You share your thoughts with the scientist sitting next to you. He smiles and says : “Well my friend, that’s all of it.” he says , sounding very dissapointed. “That’s all we know of your friend’s experience of eating an apple.” he continues — ”Frankly, this is all we’ll ever have. Science is objective and experience is subjective.” You stare at him, dumbfounded — What’s this voodoo this guy is talking about?</p><p>That voodoo, is the secret. It’s one of the biggest questions out there. How do we have subjective experience, in an objective world? Why do atoms that form into a complex structure suddenly start having subjective feelings? And even more troubling, how do we prove that consciousness is real? After all, it’s a subjective feeling.</p><p>How can the most obvious thing to us, the fact that we experience, be out of reach for scientific empirical research?</p><p>These questions may be the key to discovering the secrets of the universe. Join me for a series of articles on this subject. I’ll share my thoughts and philosophical inquiry on this deep question.</p><p>I am hoping to finish this series of articles with more knowledge about the nature of consciousness and the universe. I also hope you will learn something as well.</p><blockquote>The really hard problem of consciousness is the problem of experience. When we think and perceive there is a whir of information processing, but there is also a subjective aspect. — Chalmers</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3aacce1264b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>