급박하게 굴러가는 혀눼의 일상
article thumbnail

 

리눅스에서 Spring Framework 버전을 변경해보려고 합니다!!

칼리 리눅스에서 Spring Framework 버전을 변경하는 명령어는 존재하지 않기 때문에, 다른 방법을 찾아볼게요

 

우선 Spring Frameworksms 자바 기반 프레임워크라, Java 프로젝트의 의존성 파일을 수정해야 해요

이때 보통 Maven이나 Gradle을 통해 버전이 관리됩니다.

 

Maven 환경 기반 Spring Framework버전 변경 방법

우선 칼리리눅스에 도커를 깔아서 사용 중이기 때문에, 도커 컨테이너에 접속해 줄게요!

방법을 모르신다면 아래 링크 클릭

[docker] 리눅스 docker container 접속 방법 (tistory.com)

 

[docker] 리눅스 docker container 접속 방법

안녕하세요 혀뉍니다. 이제 docker container를 시작했으니 해당 컨테이너에 접속을 해보려고 합니다. 생각보다 컨테이너 접속 방법을 모르겠어서 많이 헤맸어요,, 컨테이너 접속 명령어 저번과 똑

hyunjiway.tistory.com

 

 

저는 Maven을 사용해 보도록 하겠습니다.

아래의 명령어를 먼저 입력해 주세요

apt-get update 
apt-get install maven 

root@b38bf0ea88f4:/helloworld# apt-get update
Get:1 http://security.debian.org/debian-security bullseye-security InRelease [48.4 kB]
Hit:2 http://deb.debian.org/debian bullseye InRelease                   
Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
Get:4 http://security.debian.org/debian-security bullseye-security/main amd64 Packages [245 kB]
Fetched 338 kB in 1s (397 kB/s) 
Reading package lists... Done
root@b38bf0ea88f4:/helloworld# apt-get install maven
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
maven is already the newest version (3.6.3-5).
0 upgraded, 0 newly installed, 0 to remove and 57 not upgraded.

이미 Maven을 사용 중임을 확인했습니다.

이제 pom.xml파일을 찾을 건데 위치를 모를 경우 find 명령어로 찾아주면 쉽겠죠?

root@b38bf0ea88f4:/helloworld# find / -name pom.xml
/usr/local/tomcat/webapps/helloworld/META-INF/maven/com.example/spring4shell-vulnerable-application/pom.xml
/helloworld/pom.xml

find 명령어로 찾았을 때 2번째에 있는 pom.xml이 변경해야 하는 파일입니다!

해당 경로에서 pom.xml파일을 열어볼게요

 

root@b38bf0ea88f4:/helloworld# cat pom.xml 
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>2.6.3</version>
                <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <packaging>war</packaging>
        <groupId>com.example</groupId>
        <artifactId>spring4shell-vulnerable-application</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>Spring4Shell Vulnerable Application</name>
        <description>Demo project for Spring Boot</description>
        <properties>
                <java.version>1.8</java.version>
        </properties>
        <dependencies>
                <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-thymeleaf
                        </artifactId>
                        <version>2.6.3</version>
                </dependency>
                <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-web</artifactId>
                        <version>2.6.3</version>
                </dependency>

                <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-test</artifactId>
                        <version>2.6.3</version>
                        <scope>test</scope>
                </dependency>

                <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                        <version>2.6.3</version>
                        <scope>provided</scope>
                </dependency>
        </dependencies>

        <build>
                <finalName>helloworld</finalName>
                <plugins>
                        <plugin>
                                <groupId>org.springframework.boot</groupId>
                                <artifactId>spring-boot-maven-plugin</artifactId>
                                <version>2.6.3</version>
                        </plugin>
                </plugins>
        </build>

</project>

<dependencies> 부분을 보면 되는데, 이걸 통해 지금 2.6.3 버전을 사용 중임을 알 수 있습니다.

 

그렇다면 새로운 버전으로 일부 변경해 볼게요

우선 가상머신 루트경로에 pom.xml이라는 메모장을 만들어 줍니다.

<dependency>
        		<groupId>org.springframework</groupId>
        		<artifactId>spring</artifactId>
        		<version>5.3.18</version>
        		<type>pom</type>
</dependency>

그리고 dependency 블록을 하나 추가해 줄게요

 

메모장 저장 후 가상머신 로컬 -> docker 컨테이너로 파일을 옮겨줄 겁니다.

┌──(root㉿kali)-[~]
└─# docker cp ~/pom.xml b38bf0ea88f4:/helloworld

docker cp [pom.xml 메모장 경로] [도커 컨테이너 id:파일 옮기는 경로]

참고로 컨테이너 id를 모르신다면 docker ps -a 명령어로 확인 가능합니다!

 

명령어를 치고 다시 컨테이너에 접속한 쉘로 가서 pom.xml 파일 내용이 변경되었는지 확인해 볼게요

 

root@b38bf0ea88f4:/helloworld# cat pom.xml 
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>2.6.3</version>
                <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <packaging>war</packaging>
        <groupId>com.example</groupId>
        <artifactId>spring4shell-vulnerable-application</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>Spring4Shell Vulnerable Application</name>
        <description>Demo project for Spring Boot</description>
        <properties>
                <java.version>1.8</java.version>
        </properties>
        <dependencies>
                <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring</artifactId>
                        <version>5.3.18</version>
                        <type>pom</type>
                </dependency>
                <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-thymeleaf
                        </artifactId>
                        <version>2.6.3</version>
                </dependency>
                <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-web</artifactId>
                        <version>2.6.3</version>
                </dependency>

                <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-test</artifactId>
                        <version>2.6.3</version>
                        <scope>test</scope>
                </dependency>

                <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                        <version>2.6.3</version>
                        <scope>provided</scope>
                </dependency>
        </dependencies>

        <build>
                <finalName>helloworld</finalName>
                <plugins>
                        <plugin>
                                <groupId>org.springframework.boot</groupId>
                                <artifactId>spring-boot-maven-plugin</artifactId>
                                <version>2.6.3</version>
                        </plugin>
                </plugins>
        </build>

</project>

dependency가 잘 추가되었음을 확인했습니다!

이대로 xml을 저장만 한다고 되는 게 아니라 새로 빌드해줘야 합니다.

 

 pom.xml이 있는 디렉터리로 이동해서 아래의 명령어를 입력해 주세요
mvn clean package 

root@b38bf0ea88f4:/helloworld# mvn clean package
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------< com.example:spring4shell-vulnerable-application >-----------
[INFO] Building Spring4Shell Vulnerable Application 0.0.1-SNAPSHOT
[INFO] --------------------------------[ war ]-------------------------------

이렇게 뜨다가 build success가 뜨면 끝!

무사히 빌드되서 너무 기뻐요

profile

급박하게 굴러가는 혀눼의 일상

@혀눼님

유익했다면 "좋아요❤️" 또는 "구독👍🏻" 부탁드려욥:)